identityserver4 - 方法 GetTokenAsync 不可用

标签 identityserver4

我正在关注 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/

相关文章:

c# - 获取用户上次访问时间

asp.net-core - IdentityServer4: [Authorize(Roles = "Admin")] 即使 JWT token 具有 {"role": "Admin"} 声明,也不授予管理员用户访问权限

c# - 如何在负载均衡器后面配置 UseCookieAuthentication

c# - Asp.net Core 2 使用 Identity Server 4 启用 Multi-Tenancy

c# - 身份服务器 4 故障排除

asp.net-core - 身份服务器 4 上的“客户端密码验证失败”错误

ios - iOS 重定向对话框中 IdentityProvider 的名称为 "(null)"

c# - aspnet.core 使用 UserManager<IdentityUser> 播种数据

openid-connect - 为什么 IdentityTokenLifetime 默认为 300 秒?

asp.net-core-2.0 - 使用 SAML 2.0 作为 SSO 的外部身份提供者的身份服务器 4