diff --git a/src/Ocelot/Authentication/Handler/Creator/AuthenticationHandlerCreator.cs b/src/Ocelot/Authentication/Handler/Creator/AuthenticationHandlerCreator.cs index cdfd5284..a21036a3 100644 --- a/src/Ocelot/Authentication/Handler/Creator/AuthenticationHandlerCreator.cs +++ b/src/Ocelot/Authentication/Handler/Creator/AuthenticationHandlerCreator.cs @@ -18,24 +18,25 @@ namespace Ocelot.Authentication.Handler.Creator { public Response Create(IApplicationBuilder app, AuthenticationOptions authOptions) { + throw new NotImplementedException(); var builder = app.New(); if (authOptions.Provider.ToLower() == "jwt") { var authenticationConfig = authOptions.Config as JwtConfig; - builder.UseJwtBearerAuthentication( + /* builder.UseJwtBearerAuthentication( new JwtBearerOptions() { Authority = authenticationConfig.Authority, Audience = authenticationConfig.Audience - }); + });*/ } else { var authenticationConfig = authOptions.Config as IdentityServerConfig; - builder.UseIdentityServerAuthentication(new IdentityServerAuthenticationOptions + /* builder.UseIdentityServerAuthentication(new IdentityServerAuthenticationOptions { Authority = authenticationConfig.ProviderRootUrl, ApiName = authenticationConfig.ApiName, @@ -43,7 +44,7 @@ namespace Ocelot.Authentication.Handler.Creator AllowedScopes = authOptions.AllowedScopes, SupportedTokens = SupportedTokens.Both, ApiSecret = authenticationConfig.ApiSecret - }); + });*/ } var authenticationNext = builder.Build(); diff --git a/src/Ocelot/DependencyInjection/ServiceCollectionExtensions.cs b/src/Ocelot/DependencyInjection/ServiceCollectionExtensions.cs index d55a8573..95ed7597 100644 --- a/src/Ocelot/DependencyInjection/ServiceCollectionExtensions.cs +++ b/src/Ocelot/DependencyInjection/ServiceCollectionExtensions.cs @@ -129,7 +129,7 @@ namespace Ocelot.DependencyInjection if (string.IsNullOrEmpty(identityServerConfiguration.CredentialsSigningCertificateLocation) || string.IsNullOrEmpty(identityServerConfiguration.CredentialsSigningCertificatePassword)) { - identityServerBuilder.AddTemporarySigningCredential(); + identityServerBuilder.AddDeveloperSigningCredential(); } else { diff --git a/src/Ocelot/Middleware/OcelotMiddlewareExtensions.cs b/src/Ocelot/Middleware/OcelotMiddlewareExtensions.cs index c9b5f536..6ac1d5a2 100644 --- a/src/Ocelot/Middleware/OcelotMiddlewareExtensions.cs +++ b/src/Ocelot/Middleware/OcelotMiddlewareExtensions.cs @@ -2,6 +2,7 @@ using System.Diagnostics; using IdentityServer4.AccessTokenValidation; using Microsoft.AspNetCore.Builder; +using Microsoft.Extensions.DependencyInjection; using Ocelot.Authentication.Middleware; using Ocelot.Cache.Middleware; using Ocelot.Claims.Middleware; @@ -38,9 +39,9 @@ namespace Ocelot.Middleware /// /// /// - public static async Task UseOcelot(this IApplicationBuilder builder) + public static async Task UseOcelot(this IApplicationBuilder builder, IServiceCollection services) { - await builder.UseOcelot(new OcelotMiddlewareConfiguration()); + await builder.UseOcelot(new OcelotMiddlewareConfiguration(), services); return builder; } @@ -51,9 +52,9 @@ namespace Ocelot.Middleware /// /// /// - public static async Task UseOcelot(this IApplicationBuilder builder, OcelotMiddlewareConfiguration middlewareConfiguration) + public static async Task UseOcelot(this IApplicationBuilder builder, OcelotMiddlewareConfiguration middlewareConfiguration, IServiceCollection services) { - await CreateAdministrationArea(builder); + await CreateAdministrationArea(builder, services); ConfigureDiagnosticListener(builder); @@ -170,7 +171,7 @@ namespace Ocelot.Middleware return ocelotConfiguration.Data; } - private static async Task CreateAdministrationArea(IApplicationBuilder builder) + private static async Task CreateAdministrationArea(IApplicationBuilder builder, IServiceCollection services) { var configuration = await CreateConfiguration(builder); @@ -185,18 +186,20 @@ namespace Ocelot.Middleware builder.Map(configuration.AdministrationPath, app => { var identityServerUrl = $"{baseSchemeUrlAndPort}/{configuration.AdministrationPath.Remove(0,1)}"; - app.UseIdentityServerAuthentication(new IdentityServerAuthenticationOptions - { - Authority = identityServerUrl, - ApiName = identityServerConfiguration.ApiName, - RequireHttpsMetadata = identityServerConfiguration.RequireHttps, - AllowedScopes = identityServerConfiguration.AllowedScopes, - SupportedTokens = SupportedTokens.Both, - ApiSecret = identityServerConfiguration.ApiSecret - }); + + services.AddAuthentication(IdentityServerAuthenticationDefaults.AuthenticationScheme) + .AddIdentityServerAuthentication(o => + { + o.Authority = identityServerUrl; + o.ApiName = identityServerConfiguration.ApiName; + o.RequireHttpsMetadata = identityServerConfiguration.RequireHttps; + o.AllowedScopes = identityServerConfiguration.AllowedScopes; + o.SupportedTokens = SupportedTokens.Both; + o.ApiSecret = identityServerConfiguration.ApiSecret; + }); app.UseIdentityServer(); - + app.UseAuthentication(); app.UseMvc(); }); } diff --git a/src/Ocelot/Ocelot.csproj b/src/Ocelot/Ocelot.csproj index 59bef209..ddac1e2c 100644 --- a/src/Ocelot/Ocelot.csproj +++ b/src/Ocelot/Ocelot.csproj @@ -1,9 +1,9 @@  - Exe netcoreapp2.0 2.0.0 + 2.0.0 This project is aimed at people using .NET running a micro services / service orientated architecture that need a unified point of entry into their system. In particular I want easy integration with IdentityServer reference and bearer tokens. We have been unable to find this in my current workplace without having to write our own Javascript middlewares to handle the IdentityServer reference tokens. We would rather use the IdentityServer code that already exists to do this. Ocelot is a bunch of middlewares in a specific order. Ocelot manipulates the HttpRequest object into a state specified by its configuration until it reaches a request builder middleware where it creates a HttpRequestMessage object which is used to make a request to a downstream service. The middleware that makes the request is the last thing in the Ocelot pipeline. It does not call the next middleware. The response from the downstream service is stored in a per request scoped repository and retrived as the requests goes back up the Ocelot pipeline. There is a piece of middleware that maps the HttpResponseMessage onto the HttpResponse object and that is returned to the client. That is basically it with a bunch of other features. Ocelot 0.0.0-dev diff --git a/test/Ocelot.AcceptanceTests/AuthenticationTests.cs b/test/Ocelot.AcceptanceTests/AuthenticationTests.cs index 64116034..0aa04b1c 100644 --- a/test/Ocelot.AcceptanceTests/AuthenticationTests.cs +++ b/test/Ocelot.AcceptanceTests/AuthenticationTests.cs @@ -275,7 +275,7 @@ namespace Ocelot.AcceptanceTests { services.AddLogging(); services.AddIdentityServer() - .AddTemporarySigningCredential() + .AddDeveloperSigningCredential() .AddInMemoryApiResources(new List { new ApiResource diff --git a/test/Ocelot.AcceptanceTests/AuthorisationTests.cs b/test/Ocelot.AcceptanceTests/AuthorisationTests.cs index 3eebd000..8b566380 100644 --- a/test/Ocelot.AcceptanceTests/AuthorisationTests.cs +++ b/test/Ocelot.AcceptanceTests/AuthorisationTests.cs @@ -259,7 +259,7 @@ namespace Ocelot.AcceptanceTests { services.AddLogging(); services.AddIdentityServer() - .AddTemporarySigningCredential() + .AddDeveloperSigningCredential() .AddInMemoryApiResources(new List { new ApiResource diff --git a/test/Ocelot.AcceptanceTests/ClaimsToHeadersForwardingTests.cs b/test/Ocelot.AcceptanceTests/ClaimsToHeadersForwardingTests.cs index babb520e..528d6410 100644 --- a/test/Ocelot.AcceptanceTests/ClaimsToHeadersForwardingTests.cs +++ b/test/Ocelot.AcceptanceTests/ClaimsToHeadersForwardingTests.cs @@ -133,7 +133,7 @@ namespace Ocelot.AcceptanceTests { services.AddLogging(); services.AddIdentityServer() - .AddTemporarySigningCredential() + .AddDeveloperSigningCredential() .AddInMemoryApiResources(new List { new ApiResource diff --git a/test/Ocelot.AcceptanceTests/ClaimsToQueryStringForwardingTests.cs b/test/Ocelot.AcceptanceTests/ClaimsToQueryStringForwardingTests.cs index 744cfab2..c75f3ce5 100644 --- a/test/Ocelot.AcceptanceTests/ClaimsToQueryStringForwardingTests.cs +++ b/test/Ocelot.AcceptanceTests/ClaimsToQueryStringForwardingTests.cs @@ -140,7 +140,7 @@ namespace Ocelot.AcceptanceTests { services.AddLogging(); services.AddIdentityServer() - .AddTemporarySigningCredential() + .AddDeveloperSigningCredential() .AddInMemoryApiResources(new List { new ApiResource diff --git a/test/Ocelot.AcceptanceTests/Ocelot.AcceptanceTests.csproj b/test/Ocelot.AcceptanceTests/Ocelot.AcceptanceTests.csproj index baa1c1c2..271823ac 100644 --- a/test/Ocelot.AcceptanceTests/Ocelot.AcceptanceTests.csproj +++ b/test/Ocelot.AcceptanceTests/Ocelot.AcceptanceTests.csproj @@ -31,6 +31,7 @@ + diff --git a/test/Ocelot.AcceptanceTests/Steps.cs b/test/Ocelot.AcceptanceTests/Steps.cs index cb408037..b482c00a 100644 --- a/test/Ocelot.AcceptanceTests/Steps.cs +++ b/test/Ocelot.AcceptanceTests/Steps.cs @@ -134,6 +134,7 @@ namespace Ocelot.AcceptanceTests .AddJsonFile("configuration.json") .AddEnvironmentVariables(); + IServiceCollection serviceCollection = new ServiceCollection(); var configuration = builder.Build(); _webHostBuilder = new WebHostBuilder(); @@ -157,15 +158,16 @@ namespace Ocelot.AcceptanceTests }; s.AddOcelot(configuration, settings); + serviceCollection = s; }) .ConfigureLogging(l => { - l.AddConsole(configuration.GetSection("Logging")); + l.AddConsole(); l.AddDebug(); }) .Configure(a => { - a.UseOcelot(ocelotMiddlewareConfig).Wait(); + a.UseOcelot(ocelotMiddlewareConfig, serviceCollection).Wait(); })); _ocelotClient = _ocelotServer.CreateClient(); diff --git a/test/Ocelot.ManualTest/Startup.cs b/test/Ocelot.ManualTest/Startup.cs index aa0661b6..89724a9d 100644 --- a/test/Ocelot.ManualTest/Startup.cs +++ b/test/Ocelot.ManualTest/Startup.cs @@ -26,6 +26,7 @@ namespace Ocelot.ManualTest } public IConfigurationRoot Configuration { get; } + public IServiceCollection Services { get; private set; } public void ConfigureServices(IServiceCollection services) { @@ -39,13 +40,14 @@ namespace Ocelot.ManualTest }; services.AddOcelot(Configuration, settings); + Services = services; } public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) { loggerFactory.AddConsole(Configuration.GetSection("Logging")); - app.UseOcelot().Wait(); + app.UseOcelot(Services).Wait(); } } } diff --git a/test/Ocelot.UnitTests/Ocelot.UnitTests.csproj b/test/Ocelot.UnitTests/Ocelot.UnitTests.csproj index 6edf87ae..26677800 100644 --- a/test/Ocelot.UnitTests/Ocelot.UnitTests.csproj +++ b/test/Ocelot.UnitTests/Ocelot.UnitTests.csproj @@ -33,6 +33,7 @@ +