Results 1 to 3 of 3

Thread: Qt app using oAuth2.0 for authentification

  1. #1
    Join Date
    Apr 2015
    Posts
    4
    Thanks
    1

    Default Qt app using oAuth2.0 for authentification

    Hi,

    I have to create an application in which the user will provide a username and a password to connect to a web server and I have to do it with oAuth2.0.
    So I created the following (by looking at Facebook and Twitter demo provided with oAuth).

    Qt Code:
    1. const char CLIENT_ID[] = "...";
    2. const char CLIENT_SECRET[] = "...";
    3. const char REQUEST_URL[] = "...";
    4. const char TOKEN_URL[] = "...";
    5.  
    6. oAuthClass::oAuthClass(QObject *parent) :
    7. QObject(parent)
    8. {
    9. O2* o2Auth = new O2(this);
    10.  
    11. o2Auth->setClientId(CLIENT_ID);
    12. o2Auth->setClientSecret(CLIENT_SECRET);
    13. o2Auth->setRequestUrl(REQUEST_URL);
    14. o2Auth->setTokenUrl(TOKEN_URL);
    15.  
    16. // Create a store object for writing the received tokens
    17. O2SettingsStore *store = new O2SettingsStore(O2_ENCRYPTION_KEY);
    18. store->setGroupKey("oAuth");
    19. o2Auth->setStore(store);
    20. }
    To copy to clipboard, switch view to plain text mode 

    And I am completely stuck there , I don't know what to do .
    I think that I have to use the O2Requestor class which permits to create post request. Something like :

    Qt Code:
    1. QNetworkAccessManager *manager;
    2. O2Requestor* o2Requestor = new O2Requestor(manager,o2Auth);
    3.  
    4. QNetworkRequest* request = new QNetworkRequest(...);
    5. /* I have the informations for the header
    6. { { "Authorization", "Basic <CLIENT_ID:CLIENT_SECRET>" },
    7. { "ContentType", "x-www-form-urlencoded" },
    8. { "grant_type", "password" },
    9. { "username", "<username>" },
    10. { "password", "<userpassword>" } }
    11.  
    12. so I can create a post request.
    13. */
    14.  
    15. o2Requestor->post(request, ...);
    To copy to clipboard, switch view to plain text mode 

    So are those steps good or am I wrond?
    In addition, there is a lot of signals / slots in O2 class. I think I have to use them if I want to know if the connection is ok, if the token must be refreshed, ...
    (If you knwon a good tutorial about how to use oAuth2.0 in Qt C++, I would appreciate a lot )
    Thanks.

  2. #2
    Join Date
    Dec 2009
    Location
    New Orleans, Louisiana
    Posts
    791
    Thanks
    13
    Thanked 153 Times in 150 Posts
    Qt products
    Qt5
    Platforms
    MacOS X

    Default Re: Qt app using oAuth2.0 for authentification

    I haven't used this personally, but found this very quickly via google search for "qt oauth2":

    https://github.com/cybercatalyst/qtoauth2

    Might be worth looking at.
    I write the best type of code possible, code that I want to write, not code that someone tells me to write!

  3. #3
    Join Date
    Jan 2013
    Location
    San Francisco, CA
    Posts
    2
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Re: Qt app using oAuth2.0 for authentification

    Things have changed quite a bit since you first asked. Now there's QNetworkAuthorization that makes it easier to authenticate Qt with Google SSO in C++. There are still a lot of caveats specific to Google, which is interesting because they announced they're about to block SSO from embedded web views, and everyone is scrambling to find a fix.

Similar Threads

  1. Replies: 7
    Last Post: 5th May 2013, 18:52

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.