how to connect signal for QOAuth2AuthorizationCodeFlow::authorizeWithBrowser?
Unsolved
General and Desktop
-
Hello Guys,
I am trying to build QAuth SSO for Facebook Login,
as we all know, Facebook does not allow HTTP redirrect, only HTTPS,
which unfortunatelly standard QOAuth2AuthorizationCodeFlow does not handle.according to https://forum.qt.io/topic/124560/oauth2-ssl-support/15
it is possible after QOAuth2AuthorizationCodeFlow::authorizeWithBrowser to change the parameter from https to http, so QOAuth2AuthorizationCodeFlow QOAuthHttpServerReplyHandler can pick it up...
so my code is:
FacebookSSO::FacebookSSO(QObject *parent) : QObject(parent) { this->facebook = new QOAuth2AuthorizationCodeFlow(this); this->facebook->setScope("public_profile,email"); connect(this->facebook, &QOAuth2AuthorizationCodeFlow::authorizeWithBrowser, &QDesktopServices::openUrl); this->facebook->setAuthorizationUrl("https://facebook.com/dialog/oauth"); // or https://graph.facebook.com/oauth/authorize ? this->facebook->setClientIdentifier("<CLIENT_ID>"); this->facebook->setAccessTokenUrl("https://graph.facebook.com/oauth/access_token"); this->facebook->setClientIdentifierSharedKey("<CLIENT_SECRET>"); QUrl redirectUri("https://127.0.0.1:5746/"); // so I set here HTTPS to generate proper url so its not rejected by Facebook API this->facebook->setModifyParametersFunction([redirectUri](QAbstractOAuth::Stage stage, QMultiMap<QString, QVariant>* parameters) { //qDebug() << "modifyParametersFunction stage=" << static_cast<int>(stage); // debugs only "1", because once when the reply message is redirected to HTTPS, then QOAuth2AuthorizationCodeFlow can not pick it up and dies there if (stage == QAbstractOAuth::Stage::RequestingAuthorization) { parameters->replace("redirect_uri", redirectUri); // here I must override the generated url for my Uri, to be exactly as I want, as its not modifiable in easy way } }); QOAuthHttpServerReplyHandler* replyHandler = new QOAuthHttpServerReplyHandler(5746, this); replyHandler->setCallbackText("<b>Reply received<b>, close the window, or perhaps automaticaly via JS window.close() ?"); this->facebook->setReplyHandler(replyHandler); connect(this->facebook, &QOAuth2AuthorizationCodeFlow::granted, [=](){ //qDebug() << __FUNCTION__ << __LINE__ << "Access Granted!"; // does not get here }); }
therefore, my only a Simple question os, how to connect to the:
QOAuth2AuthorizationCodeFlow::authorizeWithBrowser
so once this happens, I can move and do this again:
parameters->replace("redirect_uri", redirectUri); // this time I put only HTTP there
Thank you gurus!
-
Hi @shokarta
QDesktopServices::openUrl()
is not a slot. So simply wrap it in your own slot. egclass FacebookSSO : ... { ... public slots: void openUrl(const QUrl &url); } FacebookSSO::FacebookSSO(QObject *parent) : QObject(parent) { ... connect(this->facebook, &QOAuth2AuthorizationCodeFlow::authorizeWithBrowser, this, &FacebookSSO::openUrl); ... } void FacebookSSO::openUrl(const QUrl &url) { if (!QDesktopServices::openUrl(const QUrl &url)) { // handle error. } }
Cheers.