小编gav*_*vin的帖子

Web API 2 OWIN Bearer令牌的目的是什么?

我试图了解MVC 5中单页应用程序模板中新的OWIN Bearer Token身份验证过程.如果我错了请更正我,对于OAuth密码客户端身份验证流程,承载令牌身份验证通过检查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);
    }
}
Run Code Online (Sandbox Code Playgroud)

GrantReourceOwnerCredentials函数不仅使用以下行构成票证:context.Validated(ticket); 但它也组成了一个cookie标识,并使用以下行将其设置为cookie:context.Request.Context.Authentication.SignIn(cookiesIdentity);

所以我的问题是,这个函数中cookie的确切目的是什么?AuthenticationTicket不应该足够用于身份验证吗?

owin katana asp.net-mvc-5 asp.net-web-api2

36
推荐指数
1
解决办法
2万
查看次数

数据库结构设计

什么是票据和运送到地址表的工业最佳实践?人们将它们组合成1个表格还是将它们分成2个不同的表格?这是一般发票.先感谢您!

database relational-database

1
推荐指数
1
解决办法
149
查看次数