Open login page of QOAuthAuthorizationCodeFlow with QWebEngineView



  • Hi together,

    i'm trying to solve following problem.

    Description:

    I'm using the QOAuthAuthorizationCodeFlow to authenticate against a Service. For that a i have an instance oauth_ of the class QOAuthAuthorizationCodeFlow. Ok, then i'm setting all relevant attributes with member variables like:

    oauth_->set_scope(scope_);
    oauth_->setClientIdentifier(client_identifier_);
    oauth_->setAuthorizationUrl(auth_url_);
    // and so on ...
    

    Then i'm configuring several connects with signals and slots which handle the requests and responses. Everything works fine.
    Now the relevant point. Up to now i used an external browser (firefox) to authenticate against the service. Here the code

    connect(oauth_, &QOAuthAuthorizationCodeFlow::authorizeWithBrowser, &QDesktopServices::opernUrl);
    oauth_->grant();
    

    The grant() function starts the OAuth 2 procedure.

    But i don't want to use the external browser. I have to use the QWebEngineView for authentication. I found this code snippet to open a page:

    QWebEngineView *view_ = new QWebEngineView;
    view_->setUrl(QUrl("https://forum.qt.io"));
    view_->load();
    

    This also works.

    How can i connect the QWebEngineView with my QOAuthAuthorizationCodeFlow ?
    Anyone some ideas ?

    Thanks in advance
    Rjuz



  • This is a great question and I'm dealing with the same issue, did you manage to figure out the solution? It would be great to share with the rest of us in case you managed to solve this issue...

    If not, this is what I'm going to try out tomorrow:

    1. The AuthorizeWithBrowser signal has a URL as parameter:
      https://doc.qt.io/qt-5/qabstractoauth.html#authorizeWithBrowser
    2. I will create a public slot method where I create the web engine and open the page
    3. I will inject JavaScript code to automatically fill out the login form

    I will keep you posted!


Log in to reply