Asp.net core 如何手动分配用户
我有所有的索赔,我还检查了令牌是否有效。如何使用Asp.net core 如何手动分配用户,asp.net-core,.net-core,asp.net-core-mvc,Asp.net Core,.net Core,Asp.net Core Mvc,我有所有的索赔,我还检查了令牌是否有效。如何使用IsAuthenticated=true和声明主体登录此新用户 var tokenHandler = new JwtSecurityTokenHandler(); var validationParameters = new TokenValidationParameters() { ValidateIssuerSigningKey = true
IsAuthenticated=true
和声明主体登录此新用户
var tokenHandler = new JwtSecurityTokenHandler();
var validationParameters = new TokenValidationParameters()
{
ValidateIssuerSigningKey = true,
IssuerSigningKey = new SymmetricSecurityKey(Encoding.ASCII.GetBytes(conf.GetSection("JWTKey").Value)),
ValidateAudience = false,
ValidateIssuer = false
}
;
SecurityToken validatedToken;
IPrincipal pr= tokenHandler.ValidateToken(token, validationParameters, out validatedToken);
var claims = tokenHandler.ReadJwtToken(token).Claims;
var claimspr = new ClaimsPrincipal(new ClaimsIdentity(cliams,"JWTAuth"));
当您使用.net内核时。您可以使用
HttpContext.SignInAsync
并将ClaimsPrincipal
作为参数传递。请参见请参见AuthenticationManager
没有signin
方法您的AuthenticationManager是这样实现的吗?私有IAAuthenticationManager AuthenticationManager{get{return HttpContext.GetOwinContext().Authentication;}}}噢,我使用的是类“AuthenticationManager”,而不是接口。还有别的办法吗?”IAAuthenticationManager对我大喊大叫,说它与我的应用程序不兼容。尝试安装旧版本也不起作用。