Asp.net web api 无法理解MVC5+;WebApi2授权

Asp.net web api 无法理解MVC5+;WebApi2授权,asp.net-web-api,oauth-2.0,asp.net-mvc-5,asp.net-web-api2,asp.net-authorization,Asp.net Web Api,Oauth 2.0,Asp.net Mvc 5,Asp.net Web Api2,Asp.net Authorization,我知道OAuth的概念是什么:用户使用授权类型、用户名和密码向服务器发送请求,在服务器上进行一些检查后,用户收到一个访问令牌。 我不明白的是我为什么要这样做: ClaimsIdentity oAuthIdentity = await _userManager.CreateIdentityAsync(user, context.Options.AuthenticationType); var ticket = new Authenticati

我知道OAuth的概念是什么:用户使用授权类型、用户名和密码向服务器发送请求,在服务器上进行一些检查后,用户收到一个访问令牌。 我不明白的是我为什么要这样做:

        ClaimsIdentity oAuthIdentity = await _userManager.CreateIdentityAsync(user,
            context.Options.AuthenticationType);
        var ticket = new AuthenticationTicket(oAuthIdentity, GenerareProperties(user));
        context.Validated(ticket);
CreateIdentityAsync
返回什么?什么是
身份验证票证
context.Validated
做什么? 另外,如果我有
oAuthIdentity
为什么还要使用
cookiesIdentity
?最后,在哪里生成访问令牌


我搜索过,但找不到一个解释此问题的网站。

CreateIdentityAsync将返回要在运行上下文的ClaimsPrincipal中使用的ClaimsEntity,该内容在

为了方便起见,
AuthenticationTicket
只是传递内容的一个包装

context.Validated
将票据中的信息添加到当前主体,并允许OWIN管道继续,而不是返回401

使用
cookiesIdentity
的原因是允许从模板中的MVC页面进行身份验证。它实际上不用于WebApi

  • 进一步阅读的一些资料来源:
    • 下面是一个很好的示例,它描述了来自RC的模板,与之类似
    • 在这里,他们的作者还分析了.NET安全性中一些看似模糊的部分