C#C
C#3y ago
Kukuba008

✅ Microsoft Graph API

Hello I need to create program that will load data from Outlook calendar, which is done using Microsoft Graph API, so i have this code:
var scopes = new[] { "https://graph.microsoft.com/.default" };

// Multi-tenant apps can use "common",
// single-tenant apps must use the tenant ID from the Azure portal
var tenantId = "teanantid";

// Values from app registration
var clientId = "clientid";
var clientSecret = "clientsecret";

// using Azure.Identity;
var options = new TokenCredentialOptions
{
    AuthorityHost = AzureAuthorityHosts.AzurePublicCloud
};

// https://learn.microsoft.com/dotnet/api/azure.identity.clientsecretcredential
var clientSecretCredential = new ClientSecretCredential(
    tenantId, clientId, clientSecret, options);

var graphClient = new GraphServiceClient(clientSecretCredential, scopes);


var x = await graphClient.Users["clientid"].Request().GetAsync();

Got from here: https://learn.microsoft.com/en-us/graph/sdks/choose-authentication-providers?tabs=CS#client-credentials-provider
But im getting this error:
Code: Authorization_RequestDenied
Message: Insufficient privileges to complete the operation.

*All the variables are filled properly, i just deleted the values here.
What should i do ?
Thanks
Learn how to choose scenario-specific authentication providers for your application.
Was this page helpful?