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. Qt6: How to solve the qt.networkauth.oauth2: Unexpected call error on oAuth
QtWS25 Last Chance

Qt6: How to solve the qt.networkauth.oauth2: Unexpected call error on oAuth

Scheduled Pinned Locked Moved Unsolved General and Desktop
qtnetworkoauth2.0
1 Posts 1 Posters 457 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.
  • C Offline
    C Offline
    chilarai
    wrote on last edited by chilarai
    #1

    I have a code to connect to Google drive using QT6 but I keep getting the error qt.networkauth.replyhandler: Error transferring https://oauth2.googleapis.com/token - server replied: qt.networkauth.oauth2: Unexpected call

    I have even implemented the suggested changes mentioned here https://stackoverflow.com/questions/63305525/cant-get-oauth-2-0-code-in-qt-app-but-is-seems-to-work-in-browser. This seem to have changed the encoding of code as expected but the end result is the same. I keep getting the same error. What am I missing?

    My redirect url is http://127.0.0.1:5476

    Google::GoogleCon(QObject *parent) : QObject(parent),
        m_networkAccessManager(new QNetworkAccessManager(this)),
        m_networkReply(nullptr),
        m_dataBuffer(new QByteArray)
    {
    
        this->google = new QOAuth2AuthorizationCodeFlow(this);
    
        this->google->setScope("email https://www.googleapis.com/auth/drive");
        connect(this->google, &QOAuth2AuthorizationCodeFlow::authorizeWithBrowser, &QDesktopServices::openUrl);
    
        this->google->setAuthorizationUrl(QUrl("https://accounts.google.com/o/oauth2/auth"));
        this->google->setClientIdentifier(<CLIENT>);
        this->google->setAccessTokenUrl(QUrl("https://oauth2.googleapis.com/token"));
        this->google->setClientIdentifierSharedKey(<SECRET>);
    
    
        this->google->setModifyParametersFunction([this](QAbstractOAuth::Stage stage, QMultiMap<QString, QVariant>* parameters)
        {
            qDebug() << "modifyParametersFunction stage=" << static_cast<int>(stage);
            if (stage == QAbstractOAuth::Stage::RequestingAuthorization)
            {
                parameters->insert("access_type", "offline");
                parameters->insert("prompt", "consent");
            }
            else if (stage == QAbstractOAuth::Stage::RequestingAccessToken)
            {
                QByteArray code = parameters->value("code").toByteArray();
                QString codeString = QUrl::fromPercentEncoding(code);
    
    
                parameters->replace("code", codeString);
    
            }
        });
    
        auto replyHandler = new QOAuthHttpServerReplyHandler(5476, this);
        this->google->setReplyHandler(replyHandler);
    
        connect(this->google, &QOAuth2AuthorizationCodeFlow::granted, [=]() {
            qDebug() << "Access Granted!";
        });
    }
    
    1 Reply Last reply
    0

    • Login

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