41 lines
1.3 KiB
C#
41 lines
1.3 KiB
C#
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); // 自定义错误码:用户禁用
|
|
//}
|
|
}
|
|
}
|
|
}
|