【发布时间】:2021-03-15 06:31:44
【问题描述】:
我拥有所有声明,并且我还检查了令牌是否有效。我如何 signin 这个新用户 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"));
【问题讨论】:
-
AuthenticationManager没有signin方法 -
你的AuthenticationManager是这样实现的吗?私人 IAuthenticationManager AuthenticationManager { get { return HttpContext.GetOwinContext().Authentication; } }
-
哦,我使用的是“AuthenticationManager”类而不是接口。有没有其他方法可以做到这一点? “IAuthenticationManager”对我大喊大叫,说它与我的应用程序不兼容。尝试安装旧版本也没有用。
标签: asp.net-core .net-core asp.net-core-mvc