tag route net example data asp all asp.net oauth asp.net-core asp.net-core-mvc

route - Servicio de autorización de OAuth en ASP.NET Core



oauth 2.0 net core (2)

En Web API 2, solía ser capaz de crear un punto final para emitir un token configurando un servidor de autorización OAuth a través del middleware como se muestra a continuación:

//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);

Tal vez me lo estoy perdiendo, pero estoy tratando de descubrir cómo hacer esto en ASP.NET Core. He revisado la fuente ( https://github.com/aspnet/Security ) pero realmente no veo nada análogo. ¿Hay una nueva forma de lograr esto? ¿Necesito crear un controlador y hacerlo yo mismo?

Veo cómo se puede configurar la autenticación OAuth a través de Middleware, pero esto se refiere a la parte de autorización donde emito reclamos desde mi API.


No pierda su tiempo buscando una alternativa OAuthAuthorizationServerMiddleware en ASP.NET Core, el equipo de ASP.NET simplemente decidió no OAuthAuthorizationServerMiddleware : https://github.com/aspnet/Security/issues/83

Sugiero echar un vistazo a AspNet.Security.OpenIdConnect.Server , una bifurcación avanzada del middleware del servidor de autorización OAuth2 que viene con Katana 3: hay una versión OWIN / Katana 3 y una versión ASP.NET Core que admite tanto la versión completa. NET Framework y .NET Core.

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(); });

Para obtener más información sobre este proyecto, recomiendo leer http://kevinchalet.com/2016/07/13/creating-your-own-openid-connect-server-with-asos-introduction/ .

¡Buena suerte!


Para cualquiera que todavía busque el servidor de autorización OAuth original en ASP.NET 5, he portado el código y la muestra original aquí: https://github.com/XacronDevelopment/oauth-aspnet

El puerto incluye compatibilidad con versiones anteriores para permitir que los servidores de recursos ASP.NET 4.x lean los tokens de acceso creados por el servidor de autorización.

Los paquetes nuget están aquí: https://www.nuget.org/packages/OAuth.AspNet.AuthServer https://www.nuget.org/packages/OAuth.AspNet.Tokens https://www.nuget.org/packages/OAuth.Owin.Tokens