更新JWT
This commit is contained in:
1 parent
bb7162aaf6
commit
3769193696
16 files changed
+224
-141
No files matched your search
@@ -29,7 +29,7 @@ namespace Store.Api.Controllers
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 登录:校验用户名/密码,签发 JWT(单点登录:同用户的新登录会使旧令牌失效)
|
||||
/// 登录:校验用户名/密码,签发 JWT(同账号支持多个独立会话)
|
||||
/// </summary>
|
||||
[HttpPost]
|
||||
[EndpointSummary("用户登录")]
|
||||
@@ -51,21 +51,21 @@ namespace Store.Api.Controllers
|
||||
new(JwtClaimTypes.UserName, user.UserName),
|
||||
};
|
||||
|
||||
TokenResult token = _tokenService.CreateToken(claims);
|
||||
TokenResult token = _tokenService.CreateToken(claims, HttpContext.Connection.RemoteIpAddress?.ToString());
|
||||
return ApiResult.Ok(token);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 退出登录:销毁当前用户的服务端在线会话,令牌立即失效
|
||||
/// 退出登录:撤销当前客户端的服务端登录会话,令牌立即失效
|
||||
/// </summary>
|
||||
[HttpPost]
|
||||
[EndpointSummary("退出登录")]
|
||||
[Authorize]
|
||||
public ApiResult<object?> Logout()
|
||||
{
|
||||
if (_currentUser.UserName is string username)
|
||||
if (_currentUser.UserName is string username && _currentUser.GetClaimValue(JwtClaimTypes.Jti) is string jti)
|
||||
{
|
||||
_onlineUserStore.SignOut(username);
|
||||
_onlineUserStore.SignOutSession(username, jti);
|
||||
}
|
||||
|
||||
return ApiResult<object?>.Ok(null);
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
@StoreHub_HostAddress = http://localhost:5295
|
||||
@StoreHub_HostAddress = http://localhost:5295
|
||||
|
||||
# ============ 认证(JWT) ============
|
||||
|
||||
### 登录:返回 accessToken(单点登录,同用户新登录会使旧 token 失效)
|
||||
### 登录:返回 token(同账号可同时登录,独立记录会话和 IP)
|
||||
# @name login
|
||||
POST {{StoreHub_HostAddress}}/api/v1/Auth/Login
|
||||
Content-Type: application/json
|
||||
@@ -16,7 +16,7 @@ Content-Type: application/json
|
||||
GET {{StoreHub_HostAddress}}/api/v1/Auth/Me
|
||||
Authorization: Bearer {{login.response.body.$.data.token}}
|
||||
|
||||
### 退出登录:销毁服务端会话,token 立即失效
|
||||
### 退出登录:仅撤销当前会话,其他客户端不受影响
|
||||
POST {{StoreHub_HostAddress}}/api/v1/Auth/Logout
|
||||
Authorization: Bearer {{login.response.body.$.data.token}}
|
||||
|
||||
|
||||
Reference in new issue
Block a user