我正在使用ASP.NET Core Web API应用程序.我正在尝试在ASP.NET Identity(内置数据库表)之上实现基于Jwt令牌的身份验证.
我已经实现了所有方案,如注册用户,登录等,但现在尝试实现刷新令牌流(访问令牌过期,客户端需要使用刷新令牌获取替换访问令牌).我看到有人正在创建新表(refreshToken)来存储刷新令牌,因此可以使用访问令牌进行验证,并生成新访问和刷新令牌
https://www.blinkingcaret.com/2018/05/30/refresh-tokens-in-asp-net-core-web-api/
我创建了新表(refreshToken)来存储刷新令牌并验证它以生成访问令牌,它工作正常,但我想看看我是否可以使用现有的AspNetUserTokens表来处理相同的场景.据我所知,AspNetUserTokens表用于确认电子邮件,忘记密码等.
我的问题是:如果有人使用AspNetUserTokens存储refreshtoken,请分享想法,因为usermanager类不公开直接令牌模型(AspNetUserTokens)并且不确定我是否使用IdentityDbContext,有什么代词和缺点?我已经实现了IdentityDbContext,但是我没有在Microsoft.AspNetCore.Identity中看到内置类来在AspNetUserTokens中存储令牌
非常感谢一些指导.
谢谢
security authentication jwt asp.net-core-identity asp.net-core-2.1
因此,我在设置 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 可能会绕过某些东西?)。
authorization claims-based-identity bearer-token openid-connect
我正在尝试从此user_id = 1查询中获取数据,但是user_id传入数据中有不同的值。
select *
from user_contacts uc
inner join contacts_email_addresses ce on uc.id=ce.contact_id
inner join contacts_phone_numbers cp on uc.id=cp.contact_id
where uc.user_id=1
and cp.user_id=1
and ce.user_id=1
and uc.contact_name like '%test%'
or uc.contact_surname like '%test%'
or ce.email_address like '%test%'
or cp.phone_number like '%test%'
Run Code Online (Sandbox Code Playgroud)