c# - 使用 ADAL 检测到 multiple_matching_tokens_detected

标签 c# azure-active-directory adal

我有一项服务使用我们使用 ADAL 检索的 Azure 访问 token 。我们有数百个客户,但出于某种原因,当我们尝试为他们检索 AuthenticationResult 时,其中有两个偶尔会生成此错误:

multiple_matching_tokens_detected: The cache contains multiple tokens satisfying the requirements. Call AcquireToken again providing more requirements (e.g. UserId).

我不知道为什么数百人中只有这两个人有这个问题,而且在网上真的找不到太多关于它的信息。我们获取 token 的代码如下所示(已简化):

AuthenticationContext authContext = new AuthenticationContext(authority, new MyCustomTokenCache());
ClientCredential credential = new ClientCredential(myClientId, myPassword);
authContext.AcquireTokenSilent(resourceUri, credential, UserIdentifier.AnyUser); 

为什么会出现此错误?解决该错误的“建议”解决方案是什么?我一直倾向于尝试通过获取这样的 token 来修复它,但我真的很想知道错误到底是什么:

authContext.AcquireTokenSilent(mr.ResourceUri, credential, new UserIdentifier("usersUPN@foo.com", UserIdentifierType.UniqueId));

最佳答案

如果这仍然相关,我遇到了与 multiple_matching_tokens_detected 错误类似的问题,我发现了这个:

https://developercommunity.visualstudio.com/content/problem/17315/cant-add-new-account-with-vsts-online-failed-to-re.html

正如 Alex 在答案中提到的那样(您需要在客户端计算机上执行此操作):

  1. 关闭所有 Visual Studio 实例(在您的情况下 - 我想关闭所有客户端应用程序)。
  2. 删除 %LOCALAPPDATA%\.IdentityService。
  3. 享受吧。

像魔术一样为我工作

关于c# - 使用 ADAL 检测到 multiple_matching_tokens_detected,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32000185/

相关文章:

c# - 如何在 C# 中移动数组的开头?

c# - 通过 msi 文件在 Windows Mobile 中部署 .Net Compact Framework 应用程序

c# - 任务并行库 (TPL) 是否处理竞争条件

node.js - 使用来自 Azure Identity 的访问 token 与 Nodejs 进行 Azure Sql 连接

c# - 使用 Azure DevOps 获取个人访问 token

entity-framework-6 - 使用 Azure Active Directory 从 Azure 网站连接到 Azure SQL?

c# - 如何将数据表的列和值复制到另一个数据表

Azure 委派和应用程序权限优先级

javascript - 无法读取用户信息 - Adal 错误无法登录

azure-active-directory - 由于在缓存中未找到 token ,无法以静默方式获取 token 。调用AcquireToken方法