How to Instantiate GraphServiceClient inside an azure function?

Fareeha Sattar Shaikh 45 Reputation points
2023-03-15T15:34:59.2833333+00:00

Hello,

I am trying to create an azure function which uses graph api to get the authenticated user's profile from azure ad.

I was able to add authentication of microsoft in the azure function app, but now when I try to create GraphServiceClient, all the resources on the internet, are not working in my case. Maybe it is due to the recent update of Microsoft Graph.

I have tried following ways,

//Method 1
var confidentialClientApplication = ConfidentialClientApplicationBuilder
                                                        .Create(Constants.AppId)
                                                        .WithTenantId(Constants.TenantId)
                                                        .WithClientSecret(Constants.ClientSecret)
                                                        .Build();


            ClientCredentialProvider clientCredentialProvider = new ClientCredentialProvider(confidentialClientApplication);

            GraphServiceClient _client = new GraphServiceClient(clientCredentialProvider);

//Method2


 ClientSecretCredential clientSecretCredential = new ClientSecretCredential(Constants.TenantId, Constants.AppId, Constants.ClientSecret);
            GraphServiceClient _client = new GraphServiceClient(clientSecretCredential, Constants.scope); ;



Even the microsoft's documentation suggests the second method, which is not working. By not working I mean, it is not even compiling, there is no such constructor in GraphServiceClient.

Kindly, suggest what should I do?

Azure Functions
Azure Functions

An Azure service that provides an event-driven serverless compute platform.

Microsoft Security | Microsoft Entra | Microsoft Entra ID
Microsoft Security | Microsoft Graph
0 comments No comments

1 answer

Sort by: Most helpful
  1. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.

    7 deleted comments

    Comments have been turned off. Learn more

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.