Details
-
Bug
-
Resolution: Invalid
-
Not Evaluated
-
None
-
6.9.0
-
None
Description
Hello,
I am switching from QOAuthHttpServerReplyHandler to QOAuthUriSchemeReplyHandler in order to be able to use https as redirect url,
so I use:
oauth_google.h:
#define REDIRECT_URI "https://127.0.0.1:5476/" class GoogleSSO : public QObject { Q_OBJECT public: explicit GoogleSSO(QObject *parent = nullptr); virtual ~GoogleSSO(); public slots: Q_INVOKABLE void authenticate(); private: QOAuth2AuthorizationCodeFlow *google; QOAuthUriSchemeReplyHandler *replyHandler; };
oauth_google.cpp:
#include "oauth2_google.h" GoogleSSO::GoogleSSO(QObject *parent) : QObject(parent) { this->google = new QOAuth2AuthorizationCodeFlow(this); this->google->setClientIdentifier(...); this->google->setClientIdentifierSharedKey(...); this->google->setState(...); this->google->responseType() = ...; this->google->setAuthorizationUrl(QUrl(...)); this->google->setRequestedScopeTokens(...); this->google->setTokenUrl(QUrl(...)); QObject::connect(this->google, &QOAuth2AuthorizationCodeFlow::authorizeWithBrowser, this, [&](const QUrl &url) { qDebug() << "URL Built:" << url; }); this->google->setModifyParametersFunction([](QAbstractOAuth::Stage stage, QMultiMap<QString, QVariant> *parameters) { if (stage == QAbstractOAuth::Stage::RequestingAuthorization) // stage when building url just before opening the browser with the very first url { qDebug() << "im in stage RequestingAuthorization"; // this works fine // The only way to get refresh_token from Google Cloud parameters->insert("access_type", "offline"); // Needed for Refresh Token (as AccessToken expires shortly) parameters->insert("prompt", "consent"); // Param required to get data everytime } else if (stage == QAbstractOAuth::Stage::RequestingAccessToken) { qDebug() << "im in stage RequestingAccessToken"; // replyHandler does not recognize it, however URL realy proper... so to my understanding QAbstractOAuth::Stage does not recognize this stage properly // Percent-decode the "code" parameter so Google can match it QByteArray code = parameters->value("code").toByteArray(); parameters->replace("code", QUrl::fromPercentEncoding(code)); // need to fix the URL syntaxt to manage spaces } else { qDebug() << "im in stage OTHER"; } }); // ERROR LOGIN QObject::connect(this->google, &QOAuth2AuthorizationCodeFlow::authorizationCallbackReceived, this, [&](const QVariantMap &data) { QString error = data.value("error").toString(); if (!error.isEmpty()) { qDebug() << "ERROR"; replyHandler->close(); } }); // SUCCESS LOGIN QObject::connect(this->google, &QOAuth2AuthorizationCodeFlow::granted, this, [this]() { qDebug() << "SUCCESS"; replyHandler->close(); }); } // Invoked externally to initiate void GoogleSSO::authenticate() { replyHandler = new QOAuthUriSchemeReplyHandler(QUrl(REDIRECT_URI), this); // or this->google instead of this? replyHandler->setRedirectUrl(QUrl(REDIRECT_URI)); this->google->setReplyHandler(replyHandler); if (replyHandler->listen()) { qDebug() << "STARTNG TO LISTEN"; this->google->grant(); // Initialize OAUTH2 Workflow } else { qDebug() << "ReplyHandler ERROR"; } } // Destroy GoogleSSO::~GoogleSSO() { //replyHandler->close(); // causes crash as during closing of app, because replyHandler doesnt exist anymore, therefore calling null pointer delete this->google; }
and the webview shows me:
- so url which was changed by QAbstractOAuth::Stage::RequestingAuthorization, however at this point the QAbstractOAuth should recognize it as Stage::RequestingAccessToken? but the replyHandler also should see this webpage... so I dont know what is realy wrong here