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. how to connect signal for QOAuth2AuthorizationCodeFlow::authorizeWithBrowser?
Forum Updated to NodeBB v4.3 + New Features

how to connect signal for QOAuth2AuthorizationCodeFlow::authorizeWithBrowser?

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 194 Views 1 Watching
  • 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.
  • S Offline
    S Offline
    shokarta
    wrote on last edited by shokarta
    #1

    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!

    1 Reply Last reply
    0
    • Paul ColbyP Offline
      Paul ColbyP Offline
      Paul Colby
      wrote on last edited by Paul Colby
      #2

      Hi @shokarta

      QDesktopServices::openUrl() is not a slot. So simply wrap it in your own slot. eg

      class 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.

      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