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.
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.