我正在尝试了解 MVC 5 中单页应用程序模板中新的 OWIN Bearer Token 身份验证过程。如果我错了,请纠正我,对于 OAuth 密码客户端身份验证流程,Bearer Token 身份验证通过检查 http 授权请求标头来工作对于承载访问令牌代码来查看请求是否经过身份验证,它不依赖 cookie 来检查特定请求是否经过身份验证。
根据这篇文章:
使用 Web API 示例进行 OWIN 不记名令牌身份验证
public override async Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context)
{
using (IdentityManager identityManager = _identityManagerFactory.CreateStoreManager())
{
if (!await identityManager.Passwords.CheckPasswordAsync(context.UserName, context.Password))
{
context.SetError("invalid_grant", "The user name or password is incorrect.");
return;
}
string userId = await identityManager.Logins.GetUserIdForLocalLoginAsync(context.UserName);
IEnumerable<Claim> claims = await GetClaimsAsync(identityManager, userId);
ClaimsIdentity oAuthIdentity = CreateIdentity(identityManager, claims,
context.Options.AuthenticationType);
ClaimsIdentity cookiesIdentity = CreateIdentity(identityManager, claims,
_cookieOptions.AuthenticationType);
AuthenticationProperties properties = await CreatePropertiesAsync(identityManager, userId);
AuthenticationTicket ticket = new AuthenticationTicket(oAuthIdentity, properties);
context.Validated(ticket);
context.Request.Context.Authentication.SignIn(cookiesIdentity);
}
}
GrantReourceOwnerCredentials 函数不仅使用以下行组成票证: context.Validated(ticket); 但它也组成一个 cookie 身份,并使用以下行将其设置为 cookie: context.Request.Context.Authentication.SignIn(cookiesIdentity);
所以我的问题是,这个函数中 cookie 的确切目的是什么?AuthenticationTicket 不应该足以用于身份验证目的吗?