It looks like you're not adding the access token to the graph client call. You can do this manually below.
It will look something along the lines of this :
var graphServiceClient = new GraphServiceClient(new DelegateAuthenticationProvider((requestMessage) =>
{
requestMessage
.Headers
.Authorization = new AuthenticationHeaderValue("bearer", result.AccessToken);
return Task.FromResult(0);
}));
Where access token is retrieved using the MSAL library using code such as :
result = await authContext.AcquireTokenAsync(resourceUri, clientId, new Uri(redirectUri), new PlatformParameters(PromptBehavior.Auto));
More info on the MSAL library can be found here : https://github.com/AzureAD/microsoft-authentication-library-for-dotnet/wiki
Or you can try utilizing the MS Graph SDK's built in functionality that utilizes the MSAL library.
You'll need to use the interactive auth provider constructor. See below :
IPublicClientApplication clientApplication = PublicClientApplicationBuilder.Create(clientId).Build();
InteractiveAuthenticationProvider authProvider = new InteractiveAuthenticationProvider(clientApplication, scopes, Prompt.SelectAccount);
Remember to mark a response as answer if it's answered your question.
Thanks,
- Frank Hu