从策略处理程序内部的数据库中获取用户声明

时间:2019-04-01 16:17:27

标签: c# .net-core

我正在尝试从数据库中找到索赔的价值。我已经注册了处理程序,并已设置所有政策。

在我的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?
    }
}

0 个答案:

没有答案