Question: How to cache the token when using GraphServiceClient with UsernamePasswordCredential
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
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?
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.