创建项目
This commit is contained in:
40
Service/Application.Web/Common/JwtHandle.cs
Normal file
40
Service/Application.Web/Common/JwtHandle.cs
Normal file
@@ -0,0 +1,40 @@
|
||||
using Microsoft.AspNetCore.Authentication.JwtBearer;
|
||||
|
||||
namespace Application.Web
|
||||
{
|
||||
/// <summary>
|
||||
/// JWT验证
|
||||
/// </summary>
|
||||
public class JwtHandle : IJwtValidator
|
||||
{
|
||||
public int Priority => 1;
|
||||
public void ValidateAsync(TokenValidatedContext context, JwtTokenInfo tokenInfo)
|
||||
{
|
||||
string userId = StateHelper.userId;
|
||||
if (string.IsNullOrEmpty(userId))
|
||||
{
|
||||
throw new JwtValidationException(
|
||||
message: "未登录",
|
||||
statusCode: 200,
|
||||
errorCode: 401); // 自定义错误码:用户禁用
|
||||
}
|
||||
//var userService = App.GetService<IUnitUserService>();
|
||||
|
||||
//var userInfo = userService.GetUserInfoAsyc(userId);
|
||||
//if (userInfo == null)
|
||||
//{
|
||||
// throw new JwtValidationException(
|
||||
// message: "未登录",
|
||||
// statusCode: 200,
|
||||
// errorCode: 401); // 自定义错误码:用户禁用
|
||||
//}
|
||||
//if (userInfo.token != StateHelper.sid)
|
||||
//{
|
||||
// throw new JwtValidationException(
|
||||
// message: "未登录",
|
||||
// statusCode: 200,
|
||||
// errorCode: 401); // 自定义错误码:用户禁用
|
||||
//}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user