使用OAuthBearerTokens与UseOAuthBearerAuthentication

Dav*_*New 49 owin katana asp.net-identity asp.net-web-api2 asp.net-identity-2

在我们的Startup课程中,我配置了以下auth服务器选项:

OAuthAuthorizationServerOptions OAuthServerOptions = new OAuthAuthorizationServerOptions()
{
    AllowInsecureHttp = true,
    TokenEndpointPath = new PathString("/api/v1/token"),
    AccessTokenExpireTimeSpan = TimeSpan.FromDays(1),
    Provider = new SimpleAuthorizationServerProvider()
};
Run Code Online (Sandbox Code Playgroud)

在此之后,我们应该使用哪个选项来实际启用承载身份验证?互联网上似乎有两种变体.

选项1:

app.UseOAuthAuthorizationServer(OAuthServerOptions);
app.UseOAuthBearerAuthentication(new OAuthBearerAuthenticationOptions());
Run Code Online (Sandbox Code Playgroud)

选项2:

app.UseOAuthBearerTokens(OAuthServerOptions);
Run Code Online (Sandbox Code Playgroud)

我对它们进行了测试,结果是一样的.

这些选项有什么区别?我们什么时候应该使用哪个?

Alb*_*lta 54

UseOAuthBearerTokens扩展方法产生两个令牌服务器,并验证令牌在同一应用程序的请求的中间件.

来自源的伪代码使用反射器:

UseOAuthAuthorizationServer(); // authorization server middleware
UseOAuthBearerAuthentication(ApplicationOAuthBearerProvider); // application bearer token middleware           
UseOAuthBearerAuthentication(ExternalOAuthBearerProvider); // external bearer token middleware
Run Code Online (Sandbox Code Playgroud)