Problem accessing my api on azure using oAuth2 authentication and c++

Disciullo John 0 Reputation points
2023-02-06T15:52:53.81+00:00

I have an api hosted on Microsoft Azure. It uses oAuth2 authentication. A desktop app I wrote using Qt (C++) tries to get a token using QOAuth2AuthorizationCodeFlow code flow. I post the following ""https://login.microsoftonline.com/TenandIdGoesHere/oauth2/v2.0/authorize" and get a callback screen that says the following: https://digitalreports.azurewebsites.net/callback?code=SuperLongCodeGoesHere&session_state=SessionStateGoesHere#

and it gives a HTTP 401 error. Access to the api works using swagger. What can be going wrong? Are there some tools I can use in azure to see what is going on during authentication?

Microsoft Entra ID
Microsoft Entra ID
A Microsoft Entra identity service that provides identity management and access control capabilities. Replaces Azure Active Directory.
19,473 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Shweta Mathur 27,616 Reputation points Microsoft Employee
    2023-02-08T05:52:42.1533333+00:00

    Hi @Disciullo John ,

    Thanks for reaching out.

    I understand you are trying to get an access token using Authorization Code flow.

    The authorization code flow has 2 parts:

    1. Call authorize end point to get the code - As you are using https://login.microsoftonline.com/{tenant}/oauth2/v2.0/authorize? endpoint which will ask user to authenticate and consent the permissions and redirect you to the URL specified in redirect_uri while registering the application which in your case is callback screen. You can copy the code from here which is used to request an access token.
    2. Then call token endpoint which redeem the code to get the token.

    In your scenario, your first step provides you code which you can copy and pass this code to token endpoint now.

    User's image

    Reference: https://learn.microsoft.com/en-us/azure/active-directory/develop/v2-oauth2-auth-code-flow

    Hope this will help.

    Thanks,

    Shweta


    Please remember to "Accept Answer" if answer helped you.