由于在缓存中未找到令牌,因此无法静默获取令牌.调用方法 AcquireToken [英] Failed to acquire token silently as no token was found in the cache. Call method AcquireToken

查看:39
本文介绍了由于在缓存中未找到令牌,因此无法静默获取令牌.调用方法 AcquireToken的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I use this code sample :https://github.com/Azure-Samples/active-directory-dotnet-graphapi-web , i know this code sample is using client library , but if i want to perfrom a query (use httpclient) directly use api calls ,i used below code to get the access token from cache :

 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));

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

But i found always threw error :Failed to acquire token silently as no token was found in the cache. Call method AcquireToken

推荐答案

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

I could reproduce your error. According to this link , it seems that code sample doesn't work when using AcquireTokenSilentAsync(use NaiveSessionCache) , Please try to modify NaiveSessionCache.cs to this .

请告诉我是否有帮助.

这篇关于由于在缓存中未找到令牌,因此无法静默获取令牌.调用方法 AcquireToken的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆