ErrorInsufficientPermissionsInAccessToken trying to update guest user profile photo Microsoft Graph

Viewed 93

I've been using Microsoft Graph to try to update the profile photo of a guest user. I've tried using postman and our own front-end and always end up with the following exception:

 Code: ErrorInsufficientPermissionsInAccessToken
      Message: Exception of type 'Microsoft.Fast.Profile.Core.Exception.ProfileAccessDeniedException' was thrown.
      Inner error:
      AdditionalData:

I am, however, able to successfully retrieve the guest user's photo with a GET on both: users/{userid}/photo/$value and me/photo/$value, but unable to update it using a PUT or PATCH request on either of the URLs on both /beta/ and /v1.0/.

The request has the following scopes defined:

 "scp": "AllSites.Read Calendars.Read Calendars.ReadWrite Calendars.ReadWrite.Shared Contacts.Read Directory.AccessAsUser.All EWS.AccessAsUser.All Files.Read.All Group.Read.All Group.ReadWrite.All Mail.Read Mail.Send MailboxSettings.Read MyFiles.Read Notes.Read Notifications.ReadWrite.CreatedByApp openid People.Read People.Read.All Place.Read.All Presence.Read.All profile Sites.Read.All Sites.Search.All Tasks.ReadWrite TermStore.Read.All User.Read User.Read.All User.ReadWrite UserActivity.ReadWrite.CreatedByApp UserNotification.ReadWrite.CreatedByApp"

Note the: User.ReadWrite as specified in the docs: profilephoto-update

I am specifically using the Id as opposed to the UserPrincipleName, so specifically: /users/{id}/photo/$value, but I get the error on both of them regardless. I am making the PUT request as follows:

 var photoBytes = Convert.FromBase64String(photoData);
 var stream = new MemoryStream(photoBytes);
 var graphServiceClient = new GraphProvider(graphToken).GraphServiceClient;
    
 return graphServiceClient.Users[userId].Photo.Content
                     .Request()
                     .PutAsync(stream);

I am able to change the profile photo of a non-guest user, but I'm unable to do so with a guest user. Is it possible that there is an issue with Microsoft.Graph itself or am I missing something.

1 Answers

Thanks for reaching out to us , could you please try to add User.ReadWrite.All permission and retry again .

Thanks

Related