tidy up and no longer hard code admin area...still one int test failing before we start looking at rebuilding auth stuff

This commit is contained in:
Tom Gardham-Pallister 2017-10-29 16:35:12 +00:00
parent 24c018721f
commit b28fc6694e
6 changed files with 13 additions and 20 deletions

View File

@ -147,13 +147,13 @@ namespace Ocelot.DependencyInjection
if (identityServerConfiguration != null)
{
services.AddIdentityServer(identityServerConfiguration);
services.AddIdentityServer(identityServerConfiguration, configurationRoot);
}
return services;
}
private static void AddIdentityServer(this IServiceCollection services, IIdentityServerConfiguration identityServerConfiguration)
private static void AddIdentityServer(this IServiceCollection services, IIdentityServerConfiguration identityServerConfiguration, IConfigurationRoot configurationRoot)
{
services.TryAddSingleton<IIdentityServerConfiguration>(identityServerConfiguration);
services.TryAddSingleton<IHashMatcher, HashMatcher>();
@ -172,8 +172,8 @@ namespace Ocelot.DependencyInjection
services.AddAuthentication(IdentityServerAuthenticationDefaults.AuthenticationScheme)
.AddIdentityServerAuthentication(o =>
{
//todo - this needs to come from the config so have to get it in here...
o.Authority = baseSchemeUrlAndPort + "/administration";
var adminPath = configurationRoot.GetValue("GlobalConfiguration:AdministrationPath", string.Empty);
o.Authority = baseSchemeUrlAndPort + adminPath;
o.ApiName = identityServerConfiguration.ApiName;
o.RequireHttpsMetadata = identityServerConfiguration.RequireHttps;
o.SupportedTokens = SupportedTokens.Both;

View File

@ -41,9 +41,9 @@ namespace Ocelot.Middleware
/// </summary>
/// <param name="builder"></param>
/// <returns></returns>
public static async Task<IApplicationBuilder> UseOcelot(this IApplicationBuilder builder, IServiceCollection services)
public static async Task<IApplicationBuilder> UseOcelot(this IApplicationBuilder builder)
{
await builder.UseOcelot(new OcelotMiddlewareConfiguration(), services);
await builder.UseOcelot(new OcelotMiddlewareConfiguration());
return builder;
}
@ -54,9 +54,9 @@ namespace Ocelot.Middleware
/// <param name="builder"></param>
/// <param name="middlewareConfiguration"></param>
/// <returns></returns>
public static async Task<IApplicationBuilder> UseOcelot(this IApplicationBuilder builder, OcelotMiddlewareConfiguration middlewareConfiguration, IServiceCollection services)
public static async Task<IApplicationBuilder> UseOcelot(this IApplicationBuilder builder, OcelotMiddlewareConfiguration middlewareConfiguration)
{
await CreateAdministrationArea(builder, services);
await CreateAdministrationArea(builder);
ConfigureDiagnosticListener(builder);
@ -173,7 +173,7 @@ namespace Ocelot.Middleware
return ocelotConfiguration.Data;
}
private static async Task CreateAdministrationArea(IApplicationBuilder builder, IServiceCollection services)
private static async Task CreateAdministrationArea(IApplicationBuilder builder)
{
var configuration = await CreateConfiguration(builder);
@ -183,7 +183,6 @@ namespace Ocelot.Middleware
{
builder.Map(configuration.AdministrationPath, app =>
{
Console.WriteLine("SETTING UP ADMIN AREA");
app.UseIdentityServer();
app.UseAuthentication();
app.UseMvc();

View File

@ -134,11 +134,8 @@ namespace Ocelot.AcceptanceTests
.AddJsonFile("configuration.json")
.AddEnvironmentVariables();
IServiceCollection serviceCollection = new ServiceCollection();
var configuration = builder.Build();
_webHostBuilder = new WebHostBuilder();
_webHostBuilder.ConfigureServices(s =>
{
s.AddSingleton(_webHostBuilder);
@ -158,7 +155,6 @@ namespace Ocelot.AcceptanceTests
};
s.AddOcelot(configuration, settings);
serviceCollection = s;
})
.ConfigureLogging(l =>
{
@ -167,7 +163,7 @@ namespace Ocelot.AcceptanceTests
})
.Configure(a =>
{
a.UseOcelot(ocelotMiddlewareConfig, serviceCollection).Wait();
a.UseOcelot(ocelotMiddlewareConfig).Wait();
}));
_ocelotClient = _ocelotServer.CreateClient();

View File

@ -42,7 +42,7 @@
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="2.0.0" />
<PackageReference Include="Microsoft.DotNet.InternalAbstractions" Version="1.0.0" />
<PackageReference Include="xunit" Version="2.3.0-beta2-build3683" />
<PackageReference Include="IdentityServer4" Version="2.0.0-rc1-update1" />
<PackageReference Include="IdentityServer4" Version="2.0.1" />
<PackageReference Include="Shouldly" Version="2.8.3" />
<PackageReference Include="TestStack.BDDfy" Version="4.3.2" />
<PackageReference Include="Consul" Version="0.7.2.3" />

View File

@ -26,7 +26,6 @@ namespace Ocelot.ManualTest
}
public IConfigurationRoot Configuration { get; }
public IServiceCollection Services { get; private set; }
public void ConfigureServices(IServiceCollection services)
{
@ -40,14 +39,13 @@ 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(Services).Wait();
app.UseOcelot().Wait();
}
}
}