Azure AD B2C Graph Api - Get/Set profile picture

流过昼夜 提交于 2021-02-08 07:09:09

问题


For one of my dashboards I want to show the user their profile picture for obvious personalisation reasons, and offer them the possibility to change it.

Most blog posts and articles on the Microsoft Docs site name a variety of endpoints I can leverage to get this data, but I'm just unable to get this to work with a simple postman call. Since I can't even get the photo, I wouldn't know how to change (update) it either.

The following endpoints don't work:

  • GET https://graph.microsoft.com/beta/users/{id}/photo/$value
  • GET https://graph.microsoft.com/beta/users/{id}/photo
  • GET https://graph.windows.net/myorganization/users/{id}/photo?api-version=1.6
  • GET https://graph.windows.net/myorganization/users/{id}/photo/$value?api-version=1.6

All of them either result in an "resource 'photo' does not exist, or 'Internal server errors' in the json response.

Note: I can query the graph api perfectly fine for other resources.


回答1:


If in the latest Graph API. Be sure you have set the correct permission in application project config for GraphScope:

For user resource: User.Read.All, User.ReadWrite.All

For group resource: Group.Read.All, Group.ReadWrite.All

For contact resource: Contacts.Read, Contacts.ReadWrite

Some tips for update photo:

Update operation in version 1.0 supports only a user's work or school mailboxes and not personal mailboxes.

Because you operate the Azure B2C tenant user, so you have to use the Azure AD Graph API(api 1.6) but the latest Graph API. In the Azure Graph API, there is not a photo property but we can get/set the thumbnail photo.




回答2:


For anyone running into the same issue with B2C, try using the "thumbnailPhoto" endpoint. This worked for me (the GET method, specifically).

https://graph.windows.net/[tenant]/users/[objectid]/thumbnailPhoto?api-version=1.6



来源:https://stackoverflow.com/questions/52452363/azure-ad-b2c-graph-api-get-set-profile-picture

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