[英]Why having cookies on token based authentication using Identity Server and asp.net core 2
[英]Why sign-in a new user when using ASP.NET Core Identity and token-based auth?
我正在将ASP.NET Core与Identity和JWT一起使用。 关于此的信息不多,因为文档没有涉及JWT的Identity,仅涉及cookie。
这里和博客上的示例通常在用户注册期间执行此操作:
// ...other stuff within the controller
var result = await _userManager.CreateAsync(user, password);
if (result.Succeeded) {
await _signInManager.SignInAsync(user, false); // <--- ???
return await generateJwt(email, user);
}
我希望在创建用户之后,无需执行其他任何操作(除了返回jwt之外)。 基于令牌的身份验证应该避免服务器端状态。
那么,使用Identity的_signInManager.SignInAsync
的目的是什么? 有必要吗?
那么,使用Identity的
_signInManager.SignInAsync
的目的是什么?
该调用是对HttpContext.SignInAsync
调用的一个瘦包装,它看起来像这样 :
await Context.SignInAsync(IdentityConstants.ApplicationScheme,
userPrincipal,
authenticationProperties ?? new AuthenticationProperties());
通过调用AddIdentity
创建的所有默认设置,最终将身份验证信息保存在名为Identity.Application
的cookie中。
有必要吗?
在您不使用基于cookie的身份验证的环境中,则没有必要。 您正在使用JWT保留身份验证信息,因此无需设置cookie。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.