ASP.NET Core 2 应用程序中的 UseOAuthBearerAuthentication 等效项是什么?

Jos*_*den 5 oauth-2.0 asp.net-core-2.0

我正在升级一个资源服务器,该服务器接受来自我们的 oAuth 服务器的访问令牌。在 .NET 4.7 中,我的启动配置如下所示:

appBuilder.UseOAuthBearerAuthentication(new OAuthBearerAuthenticationOptions());
Run Code Online (Sandbox Code Playgroud)

当我添加 Nuget 包“Microsoft.Owin.Security.OAuth”时,我收到一条警告,指出该包与目标 .NETCoreApp 不兼容。有道理,但我不确定新包是什么。

我认为我需要的包是“Microsoft.AspNetCore.Authentication.OAuth”。这允许我添加到启动:

services
     .AddAuthentication(OAuthDefaults.DisplayName)
     .AddOAuth("Bearer", options => options.AuthorizationEndpoint = "uhhh" );
Run Code Online (Sandbox Code Playgroud)

Why would I be configuring an endpoint, I just want to look for an authorization token, not actually serve them up. This looks like the setup for an oAuth server, not a recipient. Also, the old 'OAuthBearerAuthenticationOptions' class allowed me to override things like 'AccessTokenFormat' but I'm not seeing that in the new options.

Lastly, I see that there is the option to configure oauth this way:

app.UseOAuthAuthentication
Run Code Online (Sandbox Code Playgroud)

But it complains that it's Obsolete, looks like a Core 1 version of 'AddOAuth', and nothing about AccessTokenFormat.

Any ideas?

Tra*_*her 1

Core 不提供这些 API 或其关联令牌服务器的直接替代品。当前的指导是您使用 IdentityServer4 之类的服务器以及 AddJwtBearerAuthentication。