Qt6: How to solve the qt.networkauth.oauth2: Unexpected call error on oAuth
Unsolved
General and Desktop
-
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!"; }); }