0

I am using below code to update custom extension claim attribute but it is not working.

GraphServiceClient UpdateAsync() method throwing error

  var graphServiceClient = new GraphServiceClient(new DelegateAuthenticationProvider((requestMessage) =>
            {
               requestMessage.Headers.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("bearer", graphapitoken);
                return Task.FromResult(0);
            }));

var  dictionary = new System.Collections.Generic.Dictionary<string, object>();
            dictionary ["extension_clientid_moviename"] = "SampleValue";

 await graphServiceClient.Users["abcdxyz@hotmail.com"] // here I'm getting error 
                .Request()
                .UpdateAsync(new User()
                {
                    AdditionalData = dictionary
                });

Error:

Code: Request_ResourceNotFound\r\nMessage: Resource 'abcdxyz@hotmail.com' does not exist or one of its queried reference-property objects are not present.

Update 1:

I have created extensions following below article.

https://www.rahulpnath.com/blog/azure-ad-custom-attributes-and-optional-claims-from-an-asp-dot-net-application/

I have used Powershell commands to create extensions.

extension_clientid_moviename is the extension name.

S.Chandra Sekhar
  • 453
  • 3
  • 11
  • 22

1 Answers1

0

For guest users, you can not use their email to request a user, you should use their Object ID instead.

enter image description here

Also, you can add custom data to resources using extensions.

Update:

You need User.ReadWrite.All permission.

enter image description here

Go to Azure portal->App registrations->your application->API permissions to check if you have added the permission and granted admin consent.

Tony Ju
  • 14,891
  • 3
  • 17
  • 31
  • I have already created extension following article given in update 1 of question.Kindly let me know if I'm missing anything. – S.Chandra Sekhar Mar 12 '20 at 13:42
  • After using Object id as graphServiceClient.Users["ggft679-98795-4491-y770-8de77-0mjhb-5878"] I'm getting error as "Code: Authorization_RequestDenied\r\nMessage: Insufficient privileges to complete the operation" – S.Chandra Sekhar Mar 12 '20 at 16:24
  • I have tried as per suggestions. But still I'm getting same Insufficient privileges error.I have added all permissions specified by you for graph api in azure ad application but still facing issue. – S.Chandra Sekhar Mar 13 '20 at 17:15
  • @John Did you grant admin consent? – Tony Ju Mar 18 '20 at 02:03