0
votes

I have the following c# code. I am trying to read email in exchange 365 using graph api as per the following link

Reading user emails using MS Graph API C#

 IConfidentialClientApplication cca = ConfidentialClientApplicationBuilder
                  .Create("myAppId")
                  .WithTenantId("myTenantId")
                  .WithClientSecret("myClientSecret")
                  .Build();
            ClientCredentialProvider ccp = new ClientCredentialProvider(cca);
            GraphServiceClient client = new GraphServiceClient(ccp);

  var users = await client.Users.Request()
                             .GetAsync();

I executed it and got the following error:

Microsoft.Graph.ServiceException: 'Code: Authorization_RequestDenied Message: Insufficient privileges to complete the operation.

I have given the mail.read and user.read permission as per screenshot. enter image description here

enter image description here

any advices?

Thanks.

1

1 Answers

1
votes

As your code shows, you use the client credential flow which uses application permissions.

If you want to use var users = await client.Users.Request().GetAsync(); to list users, one of the application permissions need to be set.

enter image description here