我可以从 Querystring 中的令牌初始化 Owin 上下文吗?
我将 Owin 与不记名令牌一起使用,但是当我尝试授权对 HangFire 的访问时,我从用户(身份)那里得到了 null。
但我在查询字符串中有令牌。我可以用它来获取用户吗?或初始化上下文?
代码:
public class HFAuthorizationFilter : Hangfire.Dashboard.IAuthorizationFilter
{
public bool Authorize(IDictionary<string, object> owinEnvironment)
{
var context = new OwinContext(owinEnvironment);
if (context.Authentication.User == null)//always null!?
return false;
return context.Authentication.User.HasClaim(ClaimTypes.Role, "SuperAdmin")
|| context.Authentication.User.HasClaim(ClaimTypes.Role, "Admin");
}
}