ASP.NET核心中的OAuth授权服务

ASP.NET核心中的OAuth授权服务,asp.net,oauth,asp.net-core,asp.net-core-mvc,Asp.net,Oauth,Asp.net Core,Asp.net Core Mvc,在Web API 2中,您过去可以通过如下中间件设置OAuth授权服务器来创建端点以发布令牌: //Set up our auth server options. var OAuthServerOptions = new OAuthAuthorizationServerOptions() { AllowInsecureHttp = true, TokenEndpointPath = new PathStrin

在Web API 2中,您过去可以通过如下中间件设置OAuth授权服务器来创建端点以发布令牌:

//Set up our auth server options.
var OAuthServerOptions = new OAuthAuthorizationServerOptions()
            {
                AllowInsecureHttp = true,
                TokenEndpointPath = new PathString("/token"),
                AccessTokenExpireTimeSpan = TimeSpan.FromDays(1),
                Provider = new SimpleAuthorizationServerProvider()
            };

 // Sets up the token issue endpoint using the options above
 app.UseOAuthAuthorizationServer(OAuthServerOptions);
也许我错过了它,但我正试图找出如何在ASP.NET内核中实现这一点。我已经查看了源代码(),但没有看到任何类似的内容。有没有新的方法来实现这一点?我需要创建一个控制器,然后自己做吗

我知道如何通过中间件设置OAuth身份验证,但这涉及到授权部分,我从API中发布声明。

EDIT(01/28/2021):AspNet.Security.OpenIdConnect.Server已合并为3.0更新的一部分。要开始使用OpenIddict,请访问


不要浪费时间在ASP.NET核心中寻找
OAuthAuthorizationServerMiddleware
替代方案,ASP.NET团队只是决定不移植它:

我建议看看AspNet.Security.OpenIdConnect.Server,这是Katana 3附带的OAuth2授权服务器中间件的高级分支:有一个OWIN/Katana 3版本,还有一个ASP.NET核心版本,支持完整的.NET框架和.NET核心

ASP.NET Core 1.x:

app.UseOpenIdConnectServer(options =>
{
    options.AllowInsecureHttp = true;
    options.TokenEndpointPath = new PathString("/token");
    options.AccessTokenLifetime = TimeSpan.FromDays(1);
    options.TokenEndpointPath = "/token";
    options.Provider = new SimpleAuthorizationServerProvider();
});
services.AddAuthentication().AddOpenIdConnectServer(options =>
{
    options.AllowInsecureHttp = true;
    options.TokenEndpointPath = new PathString("/token");
    options.AccessTokenLifetime = TimeSpan.FromDays(1);
    options.TokenEndpointPath = "/token";
    options.Provider = new SimpleAuthorizationServerProvider();
});
ASP.NET Core 2.x:

app.UseOpenIdConnectServer(options =>
{
    options.AllowInsecureHttp = true;
    options.TokenEndpointPath = new PathString("/token");
    options.AccessTokenLifetime = TimeSpan.FromDays(1);
    options.TokenEndpointPath = "/token";
    options.Provider = new SimpleAuthorizationServerProvider();
});
services.AddAuthentication().AddOpenIdConnectServer(options =>
{
    options.AllowInsecureHttp = true;
    options.TokenEndpointPath = new PathString("/token");
    options.AccessTokenLifetime = TimeSpan.FromDays(1);
    options.TokenEndpointPath = "/token";
    options.Provider = new SimpleAuthorizationServerProvider();
});
要了解更多关于这个项目的信息,我建议阅读


祝你好运

对于仍在ASP.NET 5中寻找原始OAuth授权服务器的人,我已在此处移植了代码和原始示例:

该端口具有向后兼容性,允许ASP.NET 4.x资源服务器读取授权服务器创建的访问令牌

nuget软件包如下所示:

这正是我想要的……也许这个问题会帮助其他人找到这个项目。感谢那些致力于此的人!不客气!这仍然是一个年轻的项目,但我希望很快在NuGet.org上发布一个RC版本(我仍然需要在vNext版本中引入一些中断的分支,我还想将其向后移植到OWIN/Katana 3,因此可能还需要几周时间)。如果您有任何问题或想分享您的反馈,请在这里、GitHub或JabbR上点击我;)@精确定位,你在那里做了一些令人印象深刻的工作!我设法使用默认包构建了一个令牌提供程序,并在这里进行了详细介绍:,但我觉得OpenIdConnect服务器可能是更好的方式!以前的问题,但您可能还想查看IdentityServer4-它刚刚进入Asp.Net Core的测试版。我可以在.Net Core 2.0中实现相同的功能吗?我尝试过,但收到错误TypeLoadException:无法从程序集“Microsoft.AspNetCore.Builder.AuthenticationOptions”中加载类型“Microsoft.AspNetCore.Authentication,Version=2.0.0,Culture=neutral,PublicKeyToken=adb9793829ddae60'。也许这会有所帮助。thinktecture的identity server的答案是:谢谢@CedricDumont,我一直在寻找集成的产品,但我考虑过thinktecture。一天结束了,这可能就是我要做的。它非常可靠。Katana的授权服务器有许多未解决的bug,仍然列在Codeplex跟踪器上。我看了你的叉子一眼,似乎你都没修好。如果您仍在寻找“原始授权服务器”,请查看
AspNet.Security.OpenIdConnect.server
,它提供了相同的体验,但修复了Katana服务器的所有已知错误。