azure - 为什么 AzureServiceTokenProvider 返回过期的访问 token ?

标签 azure oauth-2.0 azure-active-directory azure-managed-identity

我尝试使用 AzureServiceTokenProvider 获取访问 token 来调用自定义服务,但它间歇性地返回过期的 token 。我了解 AzureServiceTokenProvider caches the token and retrieves a new one before expiration ,但这是全新调试 session 中的全新 token 。调试 session 示例:

当前 UTC 时间:2021 年 3 月 6 日 5:57:16 AM

enter image description here

但是返回的token已经过期了?? 世界标准时间 2021 年 3 月 6 日上午 5:27:40

enter image description here

我在本地和部署到 Azure 时都会遇到此行为,但它是间歇性的。

更新:我还根据https://github.com/Azure/azure-sdk-for-net/issues/16718的建议尝试了将forceRefresh设置为true的GetAuthenticationResultAsync。但仍然获得了相同日期 3/6/2021 5:27:40 AM 的过期 token 。

最佳答案

很难说问题是什么。最好的猜测是获取新 token 的调用失败,因此返回缓存的 token 。

但是,正如您问题中的链接所述,此方法是旧方法,不再推荐。

因此,您可以通过切换到 Azure Identity 客户端库来“解决”该问题 https://learn.microsoft.com/en-us/dotnet/api/overview/azure/identity-readme

关于azure - 为什么 AzureServiceTokenProvider 返回过期的访问 token ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66502950/

相关文章:

azure - Microsoft Graph API 获取组事件

java - 使用java通过microsoft graph访问office 365 planner

oauth-2.0 - 使用 google oauth2 获取用户个人资料

azure - 为什么要为每个 VSTS 团队项目创建单独的 AD 应用程序?

azure-active-directory - 使用 Azure Active Directory 作为 Identity Server 的外部登录

azure - Azure 中的端口 454 和 455 正在监听什么?安全扫描标记的警告

azure - 尝试使用自定义身份体验框架策略以 Azure AD B2C 用户身份登录时出现错误 70001

ruby-on-rails - omn​​iauth(自定义策略)/doorkeeper 的法拉第超时错误

Java Get access token using Client Credentials 授予和存储 token

sql-server - Azure Active Directory 与 SQL 集成身份验证