简体   繁体   中英

unable to get access token from OAuth 2.0 Authorization Code Flow

I am trying to implement OAuth 2.0 Authorization Code Flow in a multi-tenant application.

I first requested authorization for "openid profile email" scope at login.microsoftonline.com/organizations/oauth2/v2.0/authorize and then used the code I obtained along with grant_type=authorization_code , client_id , client_secret , redirect_uri for an access token at login.microsoftonline.com/organizations/oauth2/v2.0/token

The response I got contained only id_token , and token_type=Bearer . Why wasn't I given the access_token and expired_at fields?

I tried to provide the scope again at the token call but the response came back the same. The spec says it should contain the access token. I also tried /common endpoints but things are the same.

You are using the Azure AD v2.0 endpoint. You can tell this by the fact that your url has v2.0 in it.

In the v2.0 endpoint, if you only ask for scopes that are contained in the id_token (ie openid profile email) and don't ask for any other scopes (ie https://outlook.office.com/contacts.read ) you will only get back an id_token. This due to the fact that you're basically telling Azure AD that you only want profile info and aren't talking to any apis, therefore won't need an access token.

On the other hand, if you include a scope for an api (ie https://outlook.office.com/contacts.read ) you'll get back an access_code.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM