diff --git a/src/Ocelot/Authentication/Middleware/AuthenticationMiddleware.cs b/src/Ocelot/Authentication/Middleware/AuthenticationMiddleware.cs index cfd21b64..31ef6976 100644 --- a/src/Ocelot/Authentication/Middleware/AuthenticationMiddleware.cs +++ b/src/Ocelot/Authentication/Middleware/AuthenticationMiddleware.cs @@ -53,7 +53,7 @@ namespace Ocelot.Authentication.Middleware if (context.User.Identity.IsAuthenticated) { _logger.LogDebug($"Client has been authenticated for {context.Request.Path}"); - await _next.Invoke(context); + await _next.Invoke(context); } else { @@ -72,7 +72,7 @@ namespace Ocelot.Authentication.Middleware { _logger.LogTrace($"No authentication needed for {context.Request.Path}"); - await _next.Invoke(context); + await _next.Invoke(context); } } diff --git a/src/Ocelot/Configuration/Creator/AuthenticationOptionsCreator.cs b/src/Ocelot/Configuration/Creator/AuthenticationOptionsCreator.cs index d5be4eee..284ec33c 100644 --- a/src/Ocelot/Configuration/Creator/AuthenticationOptionsCreator.cs +++ b/src/Ocelot/Configuration/Creator/AuthenticationOptionsCreator.cs @@ -1,13 +1,21 @@ using Ocelot.Configuration.Builder; using Ocelot.Configuration.File; +using Ocelot.Creator.Configuration; namespace Ocelot.Configuration.Creator { public class AuthenticationOptionsCreator : IAuthenticationOptionsCreator { + private readonly IAuthenticationProviderConfigCreator _creator; + + public AuthenticationOptionsCreator(IAuthenticationProviderConfigCreator creator) + { + _creator = creator; + } + public AuthenticationOptions Create(FileReRoute fileReRoute) { - var authenticationConfig = new ConfigCreator().Create(fileReRoute.AuthenticationOptions); + var authenticationConfig = _creator.Create(fileReRoute.AuthenticationOptions); return new AuthenticationOptionsBuilder() .WithProvider(fileReRoute.AuthenticationOptions?.Provider) diff --git a/src/Ocelot/Configuration/Creator/ConfigCreator.cs b/src/Ocelot/Configuration/Creator/AuthenticationProviderConfigCreator.cs similarity index 86% rename from src/Ocelot/Configuration/Creator/ConfigCreator.cs rename to src/Ocelot/Configuration/Creator/AuthenticationProviderConfigCreator.cs index 09c7ab16..c7a25799 100644 --- a/src/Ocelot/Configuration/Creator/ConfigCreator.cs +++ b/src/Ocelot/Configuration/Creator/AuthenticationProviderConfigCreator.cs @@ -1,13 +1,15 @@ +using Ocelot.Creator.Configuration; + namespace Ocelot.Configuration.Creator { using Ocelot.Configuration.Builder; using Ocelot.Configuration.File; - public class ConfigCreator + public class AuthenticationProviderConfigCreator : IAuthenticationProviderConfigCreator { public IAuthenticationConfig Create(FileAuthenticationOptions authenticationOptions) { - if (authenticationOptions.Provider == "Jwt") + if (authenticationOptions.Provider?.ToLower() == "jwt") { return CreateJwt(authenticationOptions); } diff --git a/src/Ocelot/Configuration/Creator/FileOcelotConfigurationCreator.cs b/src/Ocelot/Configuration/Creator/FileOcelotConfigurationCreator.cs index 3b9c91d0..c6f5f4fe 100644 --- a/src/Ocelot/Configuration/Creator/FileOcelotConfigurationCreator.cs +++ b/src/Ocelot/Configuration/Creator/FileOcelotConfigurationCreator.cs @@ -31,13 +31,13 @@ namespace Ocelot.Configuration.Creator private readonly IQosProviderHouse _qosProviderHouse; private readonly IClaimsToThingCreator _claimsToThingCreator; private readonly IAuthenticationOptionsCreator _authOptionsCreator; - private IUpstreamTemplatePatternCreator _upstreamTemplatePatternCreator; - private IRequestIdKeyCreator _requestIdKeyCreator; - private IServiceProviderConfigurationCreator _serviceProviderConfigCreator; - private IQoSOptionsCreator _qosOptionsCreator; - private IReRouteOptionsCreator _fileReRouteOptionsCreator; - private IRateLimitOptionsCreator _rateLimitOptionsCreator; - private IRegionCreator _regionCreator; + private readonly IUpstreamTemplatePatternCreator _upstreamTemplatePatternCreator; + private readonly IRequestIdKeyCreator _requestIdKeyCreator; + private readonly IServiceProviderConfigurationCreator _serviceProviderConfigCreator; + private readonly IQoSOptionsCreator _qosOptionsCreator; + private readonly IReRouteOptionsCreator _fileReRouteOptionsCreator; + private readonly IRateLimitOptionsCreator _rateLimitOptionsCreator; + private readonly IRegionCreator _regionCreator; public FileOcelotConfigurationCreator( IOptions options, diff --git a/src/Ocelot/Creator/Configuration/IAuthenticationProviderConfigCreator.cs b/src/Ocelot/Creator/Configuration/IAuthenticationProviderConfigCreator.cs new file mode 100644 index 00000000..f5cd4fda --- /dev/null +++ b/src/Ocelot/Creator/Configuration/IAuthenticationProviderConfigCreator.cs @@ -0,0 +1,10 @@ +using Ocelot.Configuration; +using Ocelot.Configuration.File; + +namespace Ocelot.Creator.Configuration +{ + public interface IAuthenticationProviderConfigCreator + { + IAuthenticationConfig Create(FileAuthenticationOptions authenticationOptions); + } +} \ No newline at end of file diff --git a/src/Ocelot/DependencyInjection/ServiceCollectionExtensions.cs b/src/Ocelot/DependencyInjection/ServiceCollectionExtensions.cs index 954942dc..d55a8573 100644 --- a/src/Ocelot/DependencyInjection/ServiceCollectionExtensions.cs +++ b/src/Ocelot/DependencyInjection/ServiceCollectionExtensions.cs @@ -44,6 +44,7 @@ using System.Reflection; using System.Security.Cryptography.X509Certificates; using Microsoft.IdentityModel.Tokens; using Ocelot.Configuration; +using Ocelot.Creator.Configuration; using FileConfigurationProvider = Ocelot.Configuration.Provider.FileConfigurationProvider; namespace Ocelot.DependencyInjection @@ -71,6 +72,7 @@ namespace Ocelot.DependencyInjection services.Configure(configurationRoot); services.TryAddSingleton(); + services.TryAddSingleton(); services.TryAddSingleton(); services.TryAddSingleton(); services.TryAddSingleton(); diff --git a/test/Ocelot.ManualTest/configuration.json b/test/Ocelot.ManualTest/configuration.json index 765326cf..6d2ee544 100644 --- a/test/Ocelot.ManualTest/configuration.json +++ b/test/Ocelot.ManualTest/configuration.json @@ -14,13 +14,16 @@ }, "AuthenticationOptions": { "Provider": "IdentityServer", - "ProviderRootUrl": "http://localhost:52888", - "ApiName": "api", "AllowedScopes": [ "openid", "offline_access" ], - "ApiSecret": "secret" + "IdentityServerConfig": { + "ProviderRootUrl": "http://localhost:52888", + "ApiName": "api", + "ApiSecret": "secret", + "RequireHttps": false + } }, "AddHeadersToRequest": { "CustomerId": "Claims[CustomerId] > value", diff --git a/test/Ocelot.UnitTests/Configuration/AuthenticationOptionsCreatorTests.cs b/test/Ocelot.UnitTests/Configuration/AuthenticationOptionsCreatorTests.cs index 85245207..7e2108ee 100644 --- a/test/Ocelot.UnitTests/Configuration/AuthenticationOptionsCreatorTests.cs +++ b/test/Ocelot.UnitTests/Configuration/AuthenticationOptionsCreatorTests.cs @@ -11,13 +11,13 @@ namespace Ocelot.UnitTests.Configuration { public class AuthenticationOptionsCreatorTests { - private AuthenticationOptionsCreator _authOptionsCreator; + private readonly AuthenticationOptionsCreator _authOptionsCreator; private FileReRoute _fileReRoute; private AuthenticationOptions _result; public AuthenticationOptionsCreatorTests() { - _authOptionsCreator = new AuthenticationOptionsCreator(); + _authOptionsCreator = new AuthenticationOptionsCreator(new AuthenticationProviderConfigCreator()); } [Fact]