c# - AzureServiceTokenProvider.GetAccessTokenAsync 是否跨(提供程序的)实例缓存 token ?

标签 c# azure

文档指出:

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 the GetAccessTokenAsync 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/

相关文章:

C# 对象到 XML 字符串并返回

c# - 创建应用程序栏图标(Expression Design、Windows Phone 7)

c# - Azure 搜索索引 - 查找项目列表

c# - 正则表达式只接受 9 位数字,没有特殊字符,最多只能有 2 个前导零

azure - 如何更新 Azure 中的 Web 应用程序并始终保持应用程序运行

azure - 部署在同一个 Azure 函数应用中的多个函数是否共享冷启动?

asp.net-mvc-2 - 当我将 "<Runtime executionContext="提升的“/>”添加到我的 Web 角色定义并尝试部署时,它无法启动

c# - 查找特定子字符串中匹配的多个组

azure - H 264 基线配置文件 - Azure 媒体服务

Azure Api 管理网关消费层 - 如何查找 IP 地址