Home > OS >  How to get access token using refresh token AzureAD
How to get access token using refresh token AzureAD

Time:10-15

I want to get access token with the help of refresh token that I got previously.

I got tokens using scope: user.read offline_access openid in oauth2 endpoint: https://login.microsoftonline.com/tenant.com/v2.0/token

After a couple of hours, access token expired. Now I am trying to get this using refresh token.

But I'm unsuccessful in it, any help is much needed.

CodePudding user response:

I tried to reproduce the same in my environment and got below results:

I created one Azure AD application and added API permissions as below:

enter image description here

With below parameters, I got the tokens via Postman:

POST https://login.microsoftonline.com/tenantID/oauth2/v2.0/token

client_id:appID
grant_type:authorization_code
scope:https://graph.microsoft.com/.default
client_secret:client_secret
code:code
redirect_uri:https://jwt.ms

Response: enter image description here

In order to get access token using above refresh token, change grant type to refresh_token.

I got the access token successfully using refresh token with parameters like below:

POST https://login.microsoftonline.com/tenantID/oauth2/v2.0/token
client_id:appID
grant_type:refresh_token
refresh_token: 0.AVYA_in0zaI3eUqOQHrbrD-FUv //paste the refresh token that you got above
client_secret:client_secret //Mandatory if client is web app

Response: enter image description here

  • Related