owin - 请求访问令牌时 Owin 未通过身份验证
问题描述
我正在使用隐式授权类型,当我请求“id_token token”作为响应类型时,我的 HttpContext.Current.User 在登录后为空,导致我相信 owin 内部出现问题。如果我只有“id_token”作为响应类型就可以了。我需要告诉 owin 在某个地方获取访问令牌吗?
作为参考,我使用 .Net Framework 作为我的客户端和 identityserver4。
解决方案
为了能够通过浏览器获取令牌,您需要AllowAccessTokensViaBrowser = true
在 IdentityServer 中的客户端配置上进行设置:
new Client
{
...
AllowedGrantTypes = GrantTypes.Implicit,
AllowAccessTokensViaBrowser = true,
...
},
在 MVC 客户端的启动中,您可以将其添加access_token
为对用户的声明:
app.UseOpenIdConnectAuthentication(new OpenIdConnectAuthenticationOptions
{
...
ResponseType = "id_token token",
Notifications = new OpenIdConnectAuthenticationNotifications
{
SecurityTokenValidated = n =>
{
n.AuthenticationTicket.Identity.AddClaim(new Claim("access_token", n.ProtocolMessage.AccessToken));
return Task.FromResult(0);
}
}
});
推荐阅读
- php - 如何在 Laravel 中使用附加或同步方法在数据透视表中插入多个值
- haskell - 如何减少 lambda 表达式
- c# - 尝试将字符串转换为数组而字符串中没有任何空格 C#
- mysql - MySQL 5.7 存储过程永远运行,但通过工作台运行相同的代码运行速度很快
- git - 如何在“git log --all --graph --oneline --simplify-by-decoration”中提交日期
- java - Java 文件显示未知字符
- django - Django创建注销后不会破坏的会话
- html - 我正在尝试在 Angular js 中搜索城市但不工作
- azure - 使用 Azure API 管理模拟故障转移
- c - .bss 数据不适合分配的 RAM 大小