Rest API flow Authentication on management.azure.com scope

Andrea Romano 0 Reputation points
2024-01-31T09:02:26.9633333+00:00

Hi at all, I have a problem about authentication on production environment. In development environment I have a multi-tenant application with azure management delegate permission. I am able to get token at endpoint https://login.microsoftonline.com/organizations/oauth2/v2.0/authorize with my client id and scope like "openid https://management.azure.com//.default". After this I'am able to refresh the token using endpoint https://login.microsoftonline.com/{tenantId}/oauth2/v2.0/token with clientid, clientsecret, grant_type e refresh_token parameters In the development enviroment this flow works perfectly and I can access to azure subscription of the tenant. The same flow in production enviroment doesn't works because when I try to refresh the token with a tenant, I receive the error:

{"error":"invalid_grant","error_description":"AADSTS65001: The user or administrator has not consented to use the application with ID '****' named '*****'. Send an interactive authorization request for this user and resource. Trace ID: 63164622-725f-4cb7-ba1b-1f4027bca600 Correlation ID: 385204d6-8243-4f23-b2aa-3c85132d0409 Timestamp: 2024-01-31 16:11:20Z","error_codes":[65001],"timestamp":"2024-01-31 16:11:20Z","trace_id":"63164622-725f-4cb7-ba1b-1f4027bca600","correlation_id":"385204d6-8243-4f23-b2aa-3c85132d0409","suberror":"consent_required"}

The permission is correctly granted by administrator: User's image

I don't understand what I miss. Thanks for help, I have added correlationID Andrea

Microsoft Security Microsoft Entra Microsoft Entra ID
Microsoft Security Microsoft Identity Manager
{count} votes

1 answer

Sort by: Most helpful
  1. Navya 19,795 Reputation points Microsoft External Staff Moderator
    2024-02-09T11:39:59.2+00:00

    Hi @Andrea Romano

    As per your explanation I understand you are able to get access token and refresh token, but while refresh the token you got the error AADSTS65001.

    While requesting an access token and a refresh token, you pass the scope as openid offline_access, but to obtain a refresh token, you pass the scope as https://management.azure.com//.default, which causes an error.

    The refresh token should use the scope that was used in the authorization code flow (to get access token and refresh token). To fix the error, make sure to include the scope of openID offline Access in the refresh token request.

    User's image

    And I noticed another thing in the snips that you provided. You are using https://login.microsoftonline.com/organizations/oauth2/v2.0/token endpoint to obtain the access token and refresh token. While obtain refresh token you are using specific tenant https://login.microsoftonline.com/{tenant}/oauth2/v2.0/token endpoint. The parameter values used in the authorization flow should also be passed in the refresh token.

    To more about refresh token : https://learn.microsoft.com/en-us/entra/identity-platform/v2-oauth2-auth-code-flow#refresh-the-access-token

    Hope this helps. Do let us know if you any further queries.

    Thanks, Navya.

    Please "Accept the answer" if the information helped you. This will help us and others in the community as well.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.