1
votes

For authentication, we are using below scopes as mentioned in the doc https://docs.microsoft.com/en-us/exchange/client-developer/legacy-protocols/how-to-authenticate-an-imap-pop-smtp-application-by-using-oauth

offline_access https://outlook.office.com/IMAP.AccessAsUser.All https://outlook.office.com/SMTP.Send We are able to get access_token and refresh_token successfully

We want to get userPrincipalName but https://outlook.office.com/api/v2.0/me/ api doesn't return userPrincipalName. We tried using graph api https://graph.microsoft.com/v1.0/me to get userPrincipalName however we are getting error , looks like for hitting graph api only graph scopes would work.

We tried with graph scopes urls,

https://graph.microsoft.com/IMAP.AccessAsUser.All , https://graph.microsoft.com/SMTP.Send and able to hit graph api , however smtp and imap authentication is not working with these scopes.

since Microsoft is deprecating outlook rest apis and asking to move to graph api then why graph scopes urls are not supported for SMTP and IMAP ?

Is there any way we can get the userPricipalName ?

1
When you use https://outlook.office.com/api/v2.0/me/ to get the information of the logged-in user, what error happened?Carl Zhao
@CarlZhao no error comes, we are able to get the user details successfully, however in the response , userPrincipalName is not there which we require. userPrincipalName is there in the graph api graph.microsoft.com/v1.0/me, but this gives error since the scopes are outlook scopes and not graph scopesalpha_decay
Hi, Do you have the opportunity to research my answer? was it useful to you?Carl Zhao

1 Answers

1
votes

You need to IMAP.AccessAsUser.All and SMTP.Send are added to MS graph api, and then grant admin consent.

enter image description here

Then use the auth code flow to get the access token. enter image description here

Call the /me endpoint.

enter image description here