Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. OAuth2 do not receive token

OAuth2 do not receive token

Scheduled Pinned Locked Moved Solved General and Desktop
2 Posts 1 Posters 238 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    Brunner
    wrote on last edited by
    #1

    Hi,

    I am trying to connect to the API of BimCollab Connection API .

    Using Qt's QOAuth2AuthorizationCodeFlow class.

    I get the code back after the authentication request but then the token request to the server is lost.

    When I send the URL I received via Postman, I get the token back.

    Authentication:

    collab.png

    Code snippet:

    mReplyHandler = std::make_unique<QOAuthHttpServerReplyHandler>(QHostAddress::LocalHost, 5000); //
    
      qDebug() << mReplyHandler->callback() << mReplyHandler->port();
      //
      // mReplyHandler->setCallbackPath("Callback");
      //
      mOAuth2->setModifyParametersFunction([=](QAbstractOAuth::Stage stage, QVariantMap* params) {
        switch (stage)
        {
          case QAbstractOAuth::Stage::RequestingAuthorization:
            params->insert("response_type", "code");
            params->insert("redirect_uri", "http://localhost:5000/Callback");
            params->insert("scope", "openid offline_access bcf");
            params->insert("code_challenge_method", "S256");
            break;
          case QAbstractOAuth::Stage::RequestingAccessToken:
            //
            qDebug() << "PARAMS CODE" << params->value("code");
            params->insert("code", QUrl::fromPercentEncoding(params->value("code").toByteArray()));
            break;
          case QAbstractOAuth::Stage::RequestingTemporaryCredentials:
            qDebug() << params;
            break;
          case QAbstractOAuth::Stage::RefreshingAccessToken:
            break;
          default:
            break;
        }
      });
    
      mOAuth2->setAuthorizationUrl(mAuthentication.mOauth2AuthUrl.GetQString());
      mOAuth2->setAccessTokenUrl(mAuthentication.mOauth2TokenUrl.GetQString());
      mOAuth2->setClientIdentifierSharedKey("k!xWcjad!u@L%ZWHc%%yKtMTqR%o1be@qWfWYaDL");
      mOAuth2->setClientIdentifier("PlayGround_Client");
    
    

    Console output:

    QtDebug: SSL build version =>  "OpenSSL 1.1.1m  14 Dec 2021"
    QtDebug: QSslSocket::supportsSSL() true
    QtDebug: SSL version =>  "OpenSSL 1.1.1c  28 May 2019"
    
    QtDebug: "http://127.0.0.1:5000/" 5000
    
    QtDebug: "authorization_code_grant"
    QtDebug: "resource_owner_password_credentials_grant"
    QtDebug: is ReplyHandlerServer listening ? true
    QtDebug: authorizationCallbackReceived
    QtDebug: TemporaryCredentialsReceived
    QtDebug: PARAMS CODE QVariant(QByteArray, "FE6EDAC15ED6032D998379F792CA0FF1765DD680970E56370985E1FF5DC16E82")
    QtDebug: authorizationCallbackReceived
    QtWarning: Unexpected call
    QtWarning: Error transferring https://playground.bimcollab.com/identity/connect/token - server replied: Bad Request
    
    1 Reply Last reply
    0
    • B Offline
      B Offline
      Brunner
      wrote on last edited by
      #2

      solved with

      case QAbstractOAuth::Stage::RequestingAccessToken:
              params->insert("code", params->value("code"));
              params->insert("redirect_uri", "http://localhost:5000/Callback");
              params->insert("scope", "openid offline_access bcf");
              params->insert("code_challenge_method", "S256");
              break;
      
      1 Reply Last reply
      1

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved