不要浪费你的时间寻找一个 OAuthAuthorizationServerMiddleware 在ASP.NET Core中,ASP.NET团队决定不再移植它: https://github.com/aspnet/Security/issues/83
OAuthAuthorizationServerMiddleware
我建议看看 的 AspNet.Security.OpenIdConnect.Server 强> ,Katana 3附带的OAuth2授权服务器中间件的高级分支:有一个OWIN / Katana 3版本,以及支持完整.NET框架和.NET Core的ASP.NET核心版本。
https://github.com/aspnet-contrib/AspNet.Security.OpenIdConnect.Server
的 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(); });
的 ASP.NET Core 2.x: 强>
services.AddAuthentication().AddOpenIdConnectServer(options => { options.AllowInsecureHttp = true; options.TokenEndpointPath = new PathString("/token"); options.AccessTokenLifetime = TimeSpan.FromDays(1); options.TokenEndpointPath = "/token"; options.Provider = new SimpleAuthorizationServerProvider(); });
要了解有关此项目的更多信息,我建议您阅读 http://kevinchalet.com/2016/07/13/creating-your-own-openid-connect-server-with-asos-introduction/ 。
祝好运!
对于仍在ASP.NET 5中寻找原始OAuth授权服务器的任何人,我已将代码和原始示例移植到此处: https://github.com/XacronDevelopment/oauth-aspnet
该端口包含向后兼容性,以允许ASP.NET 4.x资源服务器读取授权服务器创建的访问令牌。
nuget包在这里: https://www.nuget.org/packages/OAuth.AspNet.AuthServer https://www.nuget.org/packages/OAuth.AspNet.Tokens https://www.nuget.org/packages/OAuth.Owin.Tokens