diff --git a/src/Ocelot/DependencyInjection/ServiceCollectionExtensions.cs b/src/Ocelot/DependencyInjection/ServiceCollectionExtensions.cs index ccd63e64..825edea4 100644 --- a/src/Ocelot/DependencyInjection/ServiceCollectionExtensions.cs +++ b/src/Ocelot/DependencyInjection/ServiceCollectionExtensions.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; using System.Net.Http; using CacheManager.Core; +using IdentityServer4.AccessTokenValidation; using IdentityServer4.Models; using IdentityServer4.Test; using Microsoft.AspNetCore.Hosting; @@ -53,16 +54,13 @@ namespace Ocelot.DependencyInjection } public static IServiceCollection AddOcelot(this IServiceCollection services, IConfigurationRoot configurationRoot) - { - return AddOcelot(services, configurationRoot, null); - } - - public static IServiceCollection AddOcelot(this IServiceCollection services, IConfigurationRoot configurationRoot, IIdentityServerConfiguration identityServerConfiguration) { services.Configure(configurationRoot); services.AddSingleton(); services.AddSingleton(); services.AddSingleton(); + + var identityServerConfiguration = GetIdentityServerConfiguration(); if(identityServerConfiguration != null) { @@ -143,5 +141,29 @@ namespace Ocelot.DependencyInjection return services; } + + private static IdentityServerConfiguration GetIdentityServerConfiguration() + { + var username = Environment.GetEnvironmentVariable("OCELOT_USERNAME"); + var hash = Environment.GetEnvironmentVariable("OCELOT_HASH"); + var salt = Environment.GetEnvironmentVariable("OCELOT_SALT"); + + return new IdentityServerConfiguration( + "admin", + false, + SupportedTokens.Both, + "secret", + new List {"admin", "openid", "offline_access"}, + "Ocelot Administration", + true, + GrantTypes.ResourceOwnerPassword, + AccessTokenType.Jwt, + false, + new List + { + new User("admin", username, hash, salt) + } + ); + } } } diff --git a/test/Ocelot.ManualTest/Startup.cs b/test/Ocelot.ManualTest/Startup.cs index c1277af7..3c6d2949 100644 --- a/test/Ocelot.ManualTest/Startup.cs +++ b/test/Ocelot.ManualTest/Startup.cs @@ -1,15 +1,10 @@ using System; -using System.Collections.Generic; -using System.Threading.Tasks; using CacheManager.Core; -using IdentityServer4.AccessTokenValidation; -using IdentityServer4.Models; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; -using Ocelot.Configuration.Provider; using Ocelot.DependencyInjection; using Ocelot.Middleware; using ConfigurationBuilder = Microsoft.Extensions.Configuration.ConfigurationBuilder; @@ -18,8 +13,6 @@ namespace Ocelot.ManualTest { public class Startup { - private IIdentityServerConfiguration _identityServerConfig; - public Startup(IHostingEnvironment env) { var builder = new ConfigurationBuilder() @@ -46,29 +39,7 @@ namespace Ocelot.ManualTest }; services.AddOcelotOutputCaching(settings); - - var username = Environment.GetEnvironmentVariable("OCELOT_USERNAME"); - var hash = Environment.GetEnvironmentVariable("OCELOT_HASH"); - var salt = Environment.GetEnvironmentVariable("OCELOT_SALT"); - - _identityServerConfig = new IdentityServerConfiguration( - "admin", - false, - SupportedTokens.Both, - "secret", - new List {"admin", "openid", "offline_access"}, - "Ocelot Administration", - true, - GrantTypes.ResourceOwnerPassword, - AccessTokenType.Jwt, - false, - new List - { - new User("admin", username, hash, salt) - } - ); - - services.AddOcelot(Configuration, _identityServerConfig); + services.AddOcelot(Configuration); } public async void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)