我正在尝试从数据库中找到索赔的价值。我已经注册了处理程序,并已设置所有政策。
在我的AspNetUserClaims
表中,我有以下内容:
------------------------------------
Id | ClaimType | ClaimValue | UserId
------------------------------------
1 | userlevel | admin | 370d2ff5-44b8-4d13-a983-a7e9089c144c
------------------------------------
如何从UserLevelHandler
内部检查ClaimValue(从数据库而不是从JWT)?
public class UserLevelHandler : AuthorizationHandler<UserLevelRequirement>
{
private readonly ILogger<UserLevelHandler> _logger;
private readonly UserManager<ApplicationUser> _userManager;
public UserLevelHandler(ILogger<UserLevelHandler> logger, UserManager<ApplicationUser> userManager)
{
_logger = logger;
_userManager = userManager;
}
protected override async Task HandleRequirementAsync(AuthorizationHandlerContext context, UserLevelRequirement requirement)
{
// Use _usermanger to lookup the ClaimValue of userlevel using the context.User somehow?
}
}