UseOAuthBearerTokens和UseOAuthBearerAuthentication的区别

52

在我们的Startup类中,我配置了以下身份验证服务器选项:

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

在这之后,我们应该使用哪个选项来启用承载身份验证呢?似乎互联网上有两种变化。

选项1:

app.UseOAuthAuthorizationServer(OAuthServerOptions);
app.UseOAuthBearerAuthentication(new OAuthBearerAuthenticationOptions());

选项二:

app.UseOAuthBearerTokens(OAuthServerOptions);

我已经测试了它们两个,结果是相同的。

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

1个回答

55
< p > UseOAuthBearerTokens 扩展方法创建了令牌服务器和中间件,以验证同一应用程序中的请求的令牌。

使用反编译器的源代码伪代码:

UseOAuthAuthorizationServer(); // authorization server middleware
UseOAuthBearerAuthentication(ApplicationOAuthBearerProvider); // application bearer token middleware           
UseOAuthBearerAuthentication(ExternalOAuthBearerProvider); // external bearer token middleware

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接