jwi*_*ize 6 authorization claims-based-identity bearer-token openid-connect
因此,我在设置 IdentityServer4 时遇到了承载身份验证问题。基本上,我无法调用我的 API 资源并收到 401 错误。当我使用 access_token 添加授权标头时。我能够从我的网络请求中获取数据。
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Authorization = new
AuthenticationHeaderValue("Bearer", authToken);
var content = await
client.GetStringAsync("http://localhost:5000/localapi");
}
Run Code Online (Sandbox Code Playgroud)
我获取 auth_token 的方法是将用户声明存储在由身份服务器客户端设置证明的 SecurityTokenValidated 回调中。
Notifications = new OpenIdConnectAuthenticationNotifications
{
SecurityTokenValidated = notification =>
{
var identity = notification.AuthenticationTicket.Identity;
identity.AddClaim(claim: new Claim(type: "auth_token", value:
notification.ProtocolMessage.AccessToken));
return Task.CompletedTask;
}
}
Run Code Online (Sandbox Code Playgroud)
虽然这解决了我的授权问题,但我想确保我不会通过将我的 auth_token 存储在身份声明中来打开攻击向量。谁能告诉我这是否会带来安全问题。
我担心的原因是我能够使用 Postman 创建一个简单的请求,并手动将相同的 Bearer 授权令牌粘贴到请求中,然后发送它。响应给了我“安全”的 API 数据。这对我来说,如果有人拿到了 auth_token,他们就可以访问 API(或者 Postman 可能会绕过某些东西?)。
使用 OWIN 时,允许将访问令牌存储在声明中。它类似于 .NET Core 推荐的将它们存储在AuthenticationProperties
using RemoteAuthenticationOptions
with中的方法SaveTokens
。这两种方法都会导致令牌包含在客户端的会话 cookie 中。
附带说明一下,如果还没有减少 cookie 大小,您可以考虑利用IdentityServer4 ReferenceTokens 。
归档时间: |
|
查看次数: |
1109 次 |
最近记录: |