Azure AD - get user's profile photo, OAUTH access failure

痴心易碎 提交于 2021-01-28 08:22:49

问题


I'm trying to access the signed in user's Profile Photo in the context of an email app which uses EWS to connect to Office 365.

The app is registered on portal.azure.com with the following required permissions:

  1. Office 365 Exchange Online -> Access mailboxes as the signed-in user via Exchange Web Services
  2. Windows Azure Active Directory -> Sign in and read user profile

The EWS part works just fine, I'm able to sign the user in, get the access and refresh tokens, and perform EWS operations using "Authorization: Bearer access_token".

The part I'm having trouble with is getting the user's profile photo.

This is the docs I'm going by:

https://msdn.microsoft.com/en-us/office/office365/api/photo-rest-operations

The API endpoint I'm trying to use is:

GET https://outlook.office.com/api/v2.0/me/photo

... with "Authorization: Bearer access_token" header.

The above API returns this response:

HTTP 403 {"error":{"code":"ErrorAccessDenied","message":"Access is denied. Check credentials and try again."}}

What could be wrong?

  1. According to the above docs, getting user's photo should be possible using the user.read scope.
  2. The "Sign in and read user profile" permission I mentioned above has a tooltip saying "User.Read", so I believe that's the right scope

I've tried decoding my access token at jwt.io, it has: "scp": "full_access_as_user" - where is my User.Read scope, or does "full access" include "user.read"?

Any ideas?


回答1:


This is because that you tried use v2 endpoint Rest API but you didn't register the Application with v2 endpoint.

User Photo API is only available on Azure AD v2 authentication endpoint, Not Azure AD and Oauth:

You need to go to Microsoft Application Registration Portal to register your Application. For more details , you can refer to this document.




回答2:


Just for the record:

Since we were not able to use OAUTH2 APIs for this -

  • since and our app uses EWS (Exchange Web Services) already...

We just ended up using the GetUserPhoto command with the user's (account's) own email address.

Works fine.



来源:https://stackoverflow.com/questions/48216781/azure-ad-get-users-profile-photo-oauth-access-failure

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!