文档指出:
The
AzureServiceTokenProvider
class caches the token in memory and retrieves it from Azure AD just before expiration. So, you no longer have to check the expiration before calling theGetAccessTokenAsync
method. Just call the method when you want to use the token.
即使我每次使用新的 AzureServiceTokenProvider
实例也是如此,还是需要使用相同的实例?
var tokenProvider = new AzureServiceTokenProvider();
_accessToken = await tokenProvider.GetAccessTokenAsync(_msiOptions.AppId);
最佳答案
是的。缓存是静态的,因此可以在实例之间共享。
token 提供程序使用此类作为缓存:https://github.com/Azure/azure-sdk-for-net/blob/ddda7cb74b979f03bb03e240c06c924914ee8bdd/src/SdkCommon/AppAuthentication/Azure.Services.AppAuthentication/Cache/AccessTokenCache.cs .
如您所见,它有一个静态 ConcurrentDictionary。
关于c# - AzureServiceTokenProvider.GetAccessTokenAsync 是否跨(提供程序的)实例缓存 token ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58099706/