我正在关注 IdentityServer4 的快速入门。当我实现“切换到混合流并添加 API 访问”教程时,我发现获取访问 token 的方法是:
ViewContext.HttpContext.Authentication.GetTokenAsync("access_token")
不可用。有人知道我必须使用什么方法吗?谢谢。
最佳答案
问题是在我的 MVC Controller 中我有 using Microsoft.AspNetCore.Authorization;
。该库允许使用 [Authorize]
属性,但有自己的 HttpContext.Authentication 命名空间。解决方案是添加 using Microsoft.AspNetCore.Authentication
,现在我可以访问 GetTokenAsync 方法。
关于identityserver4 - 方法 GetTokenAsync 不可用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42394132/