Oauth2 AuthenticationError: Code not received - How to receive auth code by POST method?



  • Hi all, I am trying to create a simple app that can obtain the access_token using OAuth2.

    For this, I have followed the Qt Reddit Example as reddit also uses OAuth2. It ran successfully by showing the live feed. Now I've ported the same code to be used on a different server.

    But there's a problem - the server returns the code parameter in POST data instead of GET data (nothing seen in url bar unlike the reddit case). So my Qt app is unable to read the data and is giving the error - qt.networkauth.oauth2: AuthenticationError: Code not received.

    I can see the POST data from the Network tab in Firefox. If I manually feed the code from there, the app continues and works successfully. How do I make it read the auth code from a POST response?


  • Lifetime Qt Champion

    Hi and welcome to devnet,

    You should give more information about that server that does things differently.

    What version of Qt are you using ?



  • Hi, I am using Qt 5.11.0
    May I ask what more information do you need about the server?
    It is doing everything exactly like reddit's server except for the step the one mentioned above i.e. of returning a POST response instead of a GET/redirection response


  • Lifetime Qt Champion

    Is it something that's publicly accessible ?
    Maybe one can get it to run on its own computer for testing etc.



  • Sorry @SGaist, the server is not publicly accessible yet. But I found that microsoft's oauth2 flow includes a parameter response_mode:

    • response_mode: Specifies the method that should be used to send the resulting token back to your app. Can be query or form_post. query provides the code as a query string parameter on your redirect URI, while form_post executes a POST containing the code to your redirect URI.

    So can you please use this as an alternative for testing?
    https://docs.microsoft.com/en-us/azure/active-directory/develop/active-directory-protocols-oauth-code



  • @SGaist Please have a look at the methods shown here in brief: https://stackoverflow.com/a/50848992

    I want to know if Qt's auth flow supports the form_post method. If yes, how to do it?


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.