msgraph-sdk-dotnet-auth icon indicating copy to clipboard operation
msgraph-sdk-dotnet-auth copied to clipboard

Question: How to cache the token when using GraphServiceClient with UsernamePasswordCredential

Open hanhsia opened this issue 5 years ago • 1 comments

I need to use a service account to call graph api. So the only choice is to instantiate GraphServiceClient with UsernamePasswordCredential. The code is as following: var credential = new UsernamePasswordCredential( options.UserName, options.Password, options.TenantId, options.ClientId); services.AddSingleton(x => new GraphServiceClient(credential, options.Scopes));

But it look that GraphServiceClient instance doesn't have any cache mechanism to reuse the taken. Everytime I call the graph api, it need to request a token. it makes me easy to report following error: Azure.Identity.AuthenticationFailedException: UsernamePasswordCredential authentication failed: AADSTS50196: The server terminated an operation because it encountered a client request loop. Is there any way to avoid this issue?

hanhsia avatar Aug 11 '21 13:08 hanhsia

Hi @hanhsia

Thank you for reaching out and opening this issue. This client library will not leave the preview state. Microsoft.Graph v4 now integrates with Azure.Identity which supports a wide variety of authentication flows out of the box. We suggest that you migrate to v4 + Azure.Identity. Read more about it in this issue.

This issue won't be fixed, and the repository will be archived.

maisarissi avatar Aug 30 '21 20:08 maisarissi