The user logs in with
https://login.live.com/oauth20_authorize.srf
Parameters:
client_id=<CLIENT_ID>
response_type=code
scope=XboxLive.signin offline_access
redirect_uri=<REDIRECT_URL>
And gets an authorization_code M.R3_BAY.5530f5eb…
When using:
https://login.live.com/oauth20_token.srf
grant_type=authorization_code
client_id=<CLIENT_ID>
scope=Xboxlive.signin Xboxlive.offline_access
code=M.R3_BAY.5530f5eb...
redirect_uri=https://localhost/oauth_success
client_secret=<CLIENT_SECRET>
Getting access_token and refresh_token.
I want to use one of these tokens to get another access_token and refresh_token of scopes {https://graph.microsoft.com/.default openid offline_access}. I don’t want the user to reauthenticate.
Something like that:
https://login.microsoftonline.com/common/oauth2/v2.0/token
client_id=<CLIENT_ID>
scope=https://graph.microsoft.com/.default openid offline_access
refresh_token=M.R3_BL2.-CTnwtvT1!SRhk...
grant_type=refresh_token
client_secret=<CLIENT_SECRET>
But it gives me: The request was denied because one or more scopes requested are unauthorized or expired. The user must first sign in and grant the client application access to the requested scope
- I have found how to do this in MSAL using WithExtraScopeToConsent. But I’ve only found this in MSAL.NET and MSAL.JS. I couldn’t find it in MSAL4J. But I’d like to do it with a simple request, without using third-party libraries.
2
Answers
From the screenshot it looks like the "&" is missing in the code, here is the sample code for getting the access token:
For more information: https://learn.microsoft.com/en-us/azure/active-directory/develop/v2-oauth2-on-behalf-of-flow#example
I tried to reproduce the same in my environment and got the results as below:
I generated the auth code using below authorize endpoint:
I generated the access token using authorization code flow as below:
Now by using On-Behalf-Of flow, I generated the access token using below parameters:
Reference:
GitHub – A Java Web API that calls another web API with the Microsoft identity platform using the On-Behalf-Of flow