© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•4y ago•
19 replies
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();
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.
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
Choose a Microsoft Graph authentication provider - Microsoft Graph
Learn how to choose scenario-specific authentication providers for your application.
Choose a Microsoft Graph authentication provider - Microsoft Graph
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Microsoft Graph – Handling DeleteAsync Response?
C#CC# / help
5mo ago
Microsoft Graph without Azure admin
C#CC# / help
2y ago
❔ Microsoft Graph SDK - Serializing objects
C#CC# / help
3y ago
Multiple Change Notification from Microsoft Graph
C#CC# / help
5mo ago