microsoftgraph / msgraph-sdk-dotnet-auth

Archived - use the TokenCredential classes provided by Azure.Identity. https://docs.microsoft.com/en-us/dotnet/api/overview/azure/identity-readme
https://graph.microsoft.com
MIT License
78 stars 19 forks source link

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

Closed hanhsia closed 3 years ago

hanhsia commented 3 years ago

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?

maisarissi commented 3 years ago

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.