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

标签 azure-active-directory adal

我使用此代码示例:https://github.com/Azure-Samples/active-directory-dotnet-graphapi-web ,我知道此代码示例正在使用客户端库,但如果我想直接使用 api 调用执行查询(使用 httpclient),我使用下面的代码从缓存中获取访问 token :

 string userObjectID = ClaimsPrincipal.Current.FindFirst("http://schemas.microsoft.com/identity/claims/objectidentifier").Value; 
 AuthenticationContext authContext = new AuthenticationContext(Startup.Authority, new NaiveSessionCache(userObjectID)); 
 ClientCredential credential = new ClientCredential(clientId, appKey); 
 var result = await authContext.AcquireTokenSilentAsync(resource, credential, new UserIdentifier(userObjectID, UserIdentifierType.UniqueId));

但我发现总是抛出错误:无法静默获取 token ,因为在缓存中找不到 token 。调用AcquireToken方法

最佳答案

我可以重现您的错误。根据this link ,使用 AcquireTokenSilentAsync(use NaiveSessionCache) 时代码示例似乎不起作用,请尝试将 NaiveSessionCache.cs 修改为 this

请告诉我是否有帮助。

关于azure-active-directory - 由于在缓存中未找到 token ,无法以静默方式获取 token 。调用AcquireToken方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42830016/

相关文章:

azure-active-directory - 无需重定向用户的 Azure AD 身份验证

Azure Active Directory 用户将 Json 反序列化为列表模型

java - 如何使用 ADAL JS 颁发的隐式授权 token 从 Web API 访问图形 API

c# - 尝试从 Azure key 保管库获取 secret 时获得未经授权

python - 查询 Log Analytics 以便它返回所有表名的列表

ios - Swift 错误 - ADAL 库

ruby-on-rails - 如何在 Azure AD 上使用 SSO 设置 RoR 应用程序

ios - 如何清除 iOS ADAL 库中的缓存

azure - 如何通过 Portal.azure.com 将用户添加到我的 AAD 租户?

azure - 对 Azure Data Lake Storage Gen 2 的 REST API 调用不起作用。给我错误 "Audience validation failed. Audience did not match"