AzureServiceTokenProvider.GetAccessTokenAsync是否在(提供程序的)实例之间缓存令牌? [英] Does AzureServiceTokenProvider.GetAccessTokenAsync cache tokens across instances (of the provider)?
问题描述
文档指出:
AzureServiceTokenProvider
类将令牌缓存在内存中,并在到期前从Azure AD检索令牌.因此,您不再需要在调用GetAccessTokenAsync
方法之前检查过期时间.要使用令牌时,只需调用该方法即可.
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
实例还是真的都需要使用同一实例吗?
Is this true even if I use a new instance of AzureServiceTokenProvider
each time, or do I need to use the same instance?
var tokenProvider = new AzureServiceTokenProvider();
_accessToken = await tokenProvider.GetAccessTokenAsync(_msiOptions.AppId);
推荐答案
是.缓存是静态的,因此可以在实例之间共享.
Yes. The cache is static so it is shared across instances.
The token provider uses this class as the cache: https://github.com/Azure/azure-sdk-for-net/blob/ddda7cb74b979f03bb03e240c06c924914ee8bdd/src/SdkCommon/AppAuthentication/Azure.Services.AppAuthentication/Cache/AccessTokenCache.cs.
如您所见,它具有静态的ConcurrentDictionary.
As you can see, it has a static ConcurrentDictionary.
这篇关于AzureServiceTokenProvider.GetAccessTokenAsync是否在(提供程序的)实例之间缓存令牌?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!