I'm using Azure AD login to obtain an access token and be able to do a request to SharePoint Online using its API REST.
I am able to get this access token but, when I try to get the refresh token, I get an error.
In this moment I am testing this using Postman.
I am doing the following:
- I start calling the next URL to get the code:
https://login.microsoftonline.com/{tenant}/oauth2/authorize?client_id={client_id}&client_secret={client_secret}&response_type=code
- When I receive the code, I do the following POST:
POST /{tenant}/oauth2/token HTTP/1.1
Host: login.microsoftonline.com
User-Agent: PostmanRuntime/7.13.0
Accept: */*
Cache-Control: no-cache
grant_type:authorization_code
client_id:{client_id}
client_secret:{client_secret}
code:{code_generated_previous_request}
redirect_uri:https://myapplication.com
resource:https://{mycompany}.sharepoint.com/
- I receive this response:
{
"token_type": "Bearer",
"scope": "AllSites.FullControl Directory.ReadWrite.All Group.ReadWrite.All Sites.FullControl.All Sites.Read.All User.Invite.All User.Read.All User.ReadWrite.All",
"expires_in": "3599",
"ext_expires_in": "3599",
"expires_on": "1559291698",
"not_before": "1559287798",
"resource": "https://{mycompany}.sharepoint.com/",
"access_token": "XXXXXXXX...",
"refresh_token": "YYYYYYYY...",
"id_token": "ZZZZZZZZ..."
}
- Finally, I try to refresh token doing the following POST:
POST /{tenant}/oauth2/token HTTP/1.1
Host: login.microsoftonline.com
User-Agent: PostmanRuntime/7.13.0
Accept: */*
Cache-Control: no-cache
grant_type:refresh_token
client_id:{client_id}
client_secret:{client_secret}
refresh_token:YYYYYYYY...
redirect_uri:https://myapplication.com
- But in this step, I get an error:
"error": "invalid_grant",
"error_description": "AADSTS70000: Provided grant is invalid or malformed.\r\nTrace ID: XXXX\r\nCorrelation ID: XXXXX\r\nTimestamp: 2019-05-31 09:35:39Z",
"error_codes": [
70000
],
"timestamp": "2019-05-31 09:35:39Z",
"trace_id": "XXXX",
"correlation_id": "XXXX"
}
I have checked with URL Encode, without URL encode, removing the client_secret and redirect_uri parameters and other things, but I always get the same error. Surely, I'm making a stupid and obvious mistake, but I don't see which one.







