mirror of
https://github.com/nsnail/Ocelot.git
synced 2025-04-20 17:42:50 +08:00
more work towards getting identity server and admin area set up
This commit is contained in:
parent
f8804f5d9d
commit
bd07af6926
18
README.md
18
README.md
@ -113,6 +113,24 @@ Currently this is the only way to get configuration into Ocelot.
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Then in your Program.cs you will want to have the following..
|
||||||
|
|
||||||
|
IWebHostBuilder builder = new WebHostBuilder();
|
||||||
|
|
||||||
|
builder.ConfigureServices(s => {
|
||||||
|
s.AddSingleton(builder);
|
||||||
|
});
|
||||||
|
|
||||||
|
builder.UseKestrel()
|
||||||
|
.UseContentRoot(Directory.GetCurrentDirectory())
|
||||||
|
.UseStartup<Startup>();
|
||||||
|
|
||||||
|
var host = builder.Build();
|
||||||
|
|
||||||
|
host.Run();
|
||||||
|
|
||||||
|
Sadly we need to inject the IWebHostBuilder interface to get the applications scheme, url and port later. I cannot
|
||||||
|
find a better way of doing this at the moment without setting this in a static or some kind of config.
|
||||||
|
|
||||||
This is pretty much all you need to get going.......more to come!
|
This is pretty much all you need to get going.......more to come!
|
||||||
|
|
||||||
|
@ -1 +1 @@
|
|||||||
{"ReRoutes":[{"DownstreamPathTemplate":"/","UpstreamPathTemplate":"/","UpstreamHttpMethod":"get","AuthenticationOptions":{"Provider":null,"ProviderRootUrl":null,"ScopeName":null,"RequireHttps":false,"AdditionalScopes":[],"ScopeSecret":null},"AddHeadersToRequest":{},"AddClaimsToRequest":{},"RouteClaimsRequirement":{},"AddQueriesToRequest":{},"RequestIdKey":null,"FileCacheOptions":{"TtlSeconds":0},"ReRouteIsCaseSensitive":false,"ServiceName":null,"DownstreamScheme":"https","DownstreamHost":"localhost","DownstreamPort":80,"QoSOptions":{"ExceptionsAllowedBeforeBreaking":0,"DurationOfBreak":0,"TimeoutValue":0},"LoadBalancer":null},{"DownstreamPathTemplate":"/","UpstreamPathTemplate":"/test","UpstreamHttpMethod":"get","AuthenticationOptions":{"Provider":null,"ProviderRootUrl":null,"ScopeName":null,"RequireHttps":false,"AdditionalScopes":[],"ScopeSecret":null},"AddHeadersToRequest":{},"AddClaimsToRequest":{},"RouteClaimsRequirement":{},"AddQueriesToRequest":{},"RequestIdKey":null,"FileCacheOptions":{"TtlSeconds":0},"ReRouteIsCaseSensitive":false,"ServiceName":null,"DownstreamScheme":"https","DownstreamHost":"localhost","DownstreamPort":80,"QoSOptions":{"ExceptionsAllowedBeforeBreaking":0,"DurationOfBreak":0,"TimeoutValue":0},"LoadBalancer":null}],"GlobalConfiguration":{"RequestIdKey":"RequestId","ServiceDiscoveryProvider":{"Provider":null,"Host":null,"Port":0},"AdministrationPath":"/administration"}}
|
{"ReRoutes":[{"DownstreamPathTemplate":"/","UpstreamPathTemplate":"/","UpstreamHttpMethod":"get","AuthenticationOptions":{"Provider":null,"ProviderRootUrl":null,"ScopeName":null,"RequireHttps":false,"AdditionalScopes":[],"ScopeSecret":null},"AddHeadersToRequest":{},"AddClaimsToRequest":{},"RouteClaimsRequirement":{},"AddQueriesToRequest":{},"RequestIdKey":null,"FileCacheOptions":{"TtlSeconds":0},"ReRouteIsCaseSensitive":false,"ServiceName":null,"DownstreamScheme":"https","DownstreamHost":"localhost","DownstreamPort":80,"QoSOptions":{"ExceptionsAllowedBeforeBreaking":0,"DurationOfBreak":0,"TimeoutValue":0},"LoadBalancer":null},{"DownstreamPathTemplate":"/","UpstreamPathTemplate":"/test","UpstreamHttpMethod":"get","AuthenticationOptions":{"Provider":null,"ProviderRootUrl":null,"ScopeName":null,"RequireHttps":false,"AdditionalScopes":[],"ScopeSecret":null},"AddHeadersToRequest":{},"AddClaimsToRequest":{},"RouteClaimsRequirement":{},"AddQueriesToRequest":{},"RequestIdKey":null,"FileCacheOptions":{"TtlSeconds":0},"ReRouteIsCaseSensitive":false,"ServiceName":null,"DownstreamScheme":"https","DownstreamHost":"localhost","DownstreamPort":80,"QoSOptions":{"ExceptionsAllowedBeforeBreaking":0,"DurationOfBreak":0,"TimeoutValue":0},"LoadBalancer":null}],"GlobalConfiguration":{"RequestIdKey":"RequestId","ServiceDiscoveryProvider":{"Provider":"test","Host":"127.0.0.1","Port":0},"AdministrationPath":"/administration"}}
|
@ -5,6 +5,7 @@ using System.Net.Http;
|
|||||||
using CacheManager.Core;
|
using CacheManager.Core;
|
||||||
using IdentityServer4.Models;
|
using IdentityServer4.Models;
|
||||||
using IdentityServer4.Test;
|
using IdentityServer4.Test;
|
||||||
|
using Microsoft.AspNetCore.Hosting;
|
||||||
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Http;
|
||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
@ -61,44 +62,49 @@ namespace Ocelot.DependencyInjection
|
|||||||
|
|
||||||
public static IServiceCollection AddOcelot(this IServiceCollection services)
|
public static IServiceCollection AddOcelot(this IServiceCollection services)
|
||||||
{
|
{
|
||||||
var authProvider = new HardCodedIdentityServerConfigurationProvider();
|
return AddOcelot(services, null);
|
||||||
var identityServerConfig = authProvider.Get();
|
}
|
||||||
|
|
||||||
services.AddIdentityServer()
|
public static IServiceCollection AddOcelot(this IServiceCollection services, IdentityServerConfiguration identityServerConfiguration)
|
||||||
.AddTemporarySigningCredential()
|
{
|
||||||
.AddInMemoryApiResources(new List<ApiResource>
|
if(identityServerConfiguration != null)
|
||||||
{
|
{
|
||||||
new ApiResource
|
services.AddIdentityServer()
|
||||||
|
.AddTemporarySigningCredential()
|
||||||
|
.AddInMemoryApiResources(new List<ApiResource>
|
||||||
{
|
{
|
||||||
Name = identityServerConfig.ApiName,
|
new ApiResource
|
||||||
Description = identityServerConfig.Description,
|
|
||||||
Enabled = identityServerConfig.Enabled,
|
|
||||||
DisplayName = identityServerConfig.ApiName,
|
|
||||||
Scopes = identityServerConfig.AllowedScopes.Select(x => new Scope(x)).ToList(),
|
|
||||||
ApiSecrets = new List<Secret>
|
|
||||||
{
|
{
|
||||||
new Secret
|
Name = identityServerConfiguration.ApiName,
|
||||||
|
Description = identityServerConfiguration.Description,
|
||||||
|
Enabled = identityServerConfiguration.Enabled,
|
||||||
|
DisplayName = identityServerConfiguration.ApiName,
|
||||||
|
Scopes = identityServerConfiguration.AllowedScopes.Select(x => new Scope(x)).ToList(),
|
||||||
|
ApiSecrets = new List<Secret>
|
||||||
{
|
{
|
||||||
Value = identityServerConfig.ApiSecret.Sha256()
|
new Secret
|
||||||
|
{
|
||||||
|
Value = identityServerConfiguration.ApiSecret.Sha256()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
})
|
||||||
})
|
.AddInMemoryClients(new List<Client>
|
||||||
.AddInMemoryClients(new List<Client>
|
|
||||||
{
|
|
||||||
new Client
|
|
||||||
{
|
{
|
||||||
ClientId = identityServerConfig.ApiName,
|
new Client
|
||||||
AllowedGrantTypes = GrantTypes.ResourceOwnerPassword,
|
{
|
||||||
ClientSecrets = new List<Secret> {new Secret(identityServerConfig.ApiSecret.Sha256())},
|
ClientId = identityServerConfiguration.ApiName,
|
||||||
AllowedScopes = identityServerConfig.AllowedScopes,
|
AllowedGrantTypes = GrantTypes.ResourceOwnerPassword,
|
||||||
AccessTokenType = identityServerConfig.AccessTokenType,
|
ClientSecrets = new List<Secret> {new Secret(identityServerConfiguration.ApiSecret.Sha256())},
|
||||||
Enabled = identityServerConfig.Enabled,
|
AllowedScopes = identityServerConfiguration.AllowedScopes,
|
||||||
RequireClientSecret = identityServerConfig.RequireClientSecret
|
AccessTokenType = identityServerConfiguration.AccessTokenType,
|
||||||
}
|
Enabled = identityServerConfiguration.Enabled,
|
||||||
})
|
RequireClientSecret = identityServerConfiguration.RequireClientSecret
|
||||||
.AddTestUsers(identityServerConfig.Users);
|
}
|
||||||
|
})
|
||||||
|
.AddTestUsers(identityServerConfiguration.Users);
|
||||||
|
}
|
||||||
|
|
||||||
services.AddMvcCore()
|
services.AddMvcCore()
|
||||||
.AddAuthorization()
|
.AddAuthorization()
|
||||||
.AddJsonFormatters();
|
.AddJsonFormatters();
|
||||||
|
@ -19,6 +19,7 @@ namespace Ocelot.Middleware
|
|||||||
using System;
|
using System;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Authorisation.Middleware;
|
using Authorisation.Middleware;
|
||||||
|
using Microsoft.AspNetCore.Hosting;
|
||||||
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Http;
|
||||||
using Microsoft.Extensions.Options;
|
using Microsoft.Extensions.Options;
|
||||||
using Ocelot.Configuration;
|
using Ocelot.Configuration;
|
||||||
@ -36,7 +37,21 @@ namespace Ocelot.Middleware
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static async Task<IApplicationBuilder> UseOcelot(this IApplicationBuilder builder)
|
public static async Task<IApplicationBuilder> UseOcelot(this IApplicationBuilder builder)
|
||||||
{
|
{
|
||||||
await builder.UseOcelot(new OcelotMiddlewareConfiguration());
|
await builder.UseOcelot(new OcelotMiddlewareConfiguration(), null);
|
||||||
|
|
||||||
|
return builder;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static async Task<IApplicationBuilder> UseOcelot(this IApplicationBuilder builder,IdentityServerConfiguration identityServerConfiguration)
|
||||||
|
{
|
||||||
|
await builder.UseOcelot(new OcelotMiddlewareConfiguration(), identityServerConfiguration);
|
||||||
|
|
||||||
|
return builder;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static async Task<IApplicationBuilder> UseOcelot(this IApplicationBuilder builder,OcelotMiddlewareConfiguration middlewareConfiguration)
|
||||||
|
{
|
||||||
|
await builder.UseOcelot(middlewareConfiguration, null);
|
||||||
|
|
||||||
return builder;
|
return builder;
|
||||||
}
|
}
|
||||||
@ -47,9 +62,9 @@ namespace Ocelot.Middleware
|
|||||||
/// <param name="builder"></param>
|
/// <param name="builder"></param>
|
||||||
/// <param name="middlewareConfiguration"></param>
|
/// <param name="middlewareConfiguration"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static async Task<IApplicationBuilder> UseOcelot(this IApplicationBuilder builder, OcelotMiddlewareConfiguration middlewareConfiguration)
|
public static async Task<IApplicationBuilder> UseOcelot(this IApplicationBuilder builder, OcelotMiddlewareConfiguration middlewareConfiguration, IdentityServerConfiguration identityServerConfiguration)
|
||||||
{
|
{
|
||||||
await CreateAdministrationArea(builder);
|
await CreateAdministrationArea(builder, identityServerConfiguration);
|
||||||
|
|
||||||
// This is registered to catch any global exceptions that are not handled
|
// This is registered to catch any global exceptions that are not handled
|
||||||
builder.UseExceptionHandlerMiddleware();
|
builder.UseExceptionHandlerMiddleware();
|
||||||
@ -153,27 +168,28 @@ namespace Ocelot.Middleware
|
|||||||
return ocelotConfiguration.Data;
|
return ocelotConfiguration.Data;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static async Task CreateAdministrationArea(IApplicationBuilder builder)
|
private static async Task CreateAdministrationArea(IApplicationBuilder builder, IdentityServerConfiguration identityServerConfiguration)
|
||||||
{
|
{
|
||||||
var configuration = await CreateConfiguration(builder);
|
var configuration = await CreateConfiguration(builder);
|
||||||
|
|
||||||
var authProvider = new HardCodedIdentityServerConfigurationProvider();
|
if(!string.IsNullOrEmpty(configuration.AdministrationPath) && identityServerConfiguration != null)
|
||||||
var identityServerConfig = authProvider.Get();
|
|
||||||
|
|
||||||
if(!string.IsNullOrEmpty(configuration.AdministrationPath))
|
|
||||||
{
|
{
|
||||||
|
var webHostBuilder = (IWebHostBuilder)builder.ApplicationServices.GetService(typeof(IWebHostBuilder));
|
||||||
|
|
||||||
|
var baseSchemeUrlAndPort = webHostBuilder.GetSetting(WebHostDefaults.ServerUrlsKey);
|
||||||
|
|
||||||
builder.Map(configuration.AdministrationPath, app =>
|
builder.Map(configuration.AdministrationPath, app =>
|
||||||
{
|
{
|
||||||
var identityServerUrl = $"http://localhost:5000/{configuration.AdministrationPath.Remove(0,1)}";
|
var identityServerUrl = $"{baseSchemeUrlAndPort}/{configuration.AdministrationPath.Remove(0,1)}";
|
||||||
|
|
||||||
app.UseIdentityServerAuthentication(new IdentityServerAuthenticationOptions
|
app.UseIdentityServerAuthentication(new IdentityServerAuthenticationOptions
|
||||||
{
|
{
|
||||||
Authority = identityServerUrl,
|
Authority = identityServerUrl,
|
||||||
ApiName = identityServerConfig.ApiName,
|
ApiName = identityServerConfiguration.ApiName,
|
||||||
RequireHttpsMetadata = identityServerConfig.RequireHttps,
|
RequireHttpsMetadata = identityServerConfiguration.RequireHttps,
|
||||||
AllowedScopes = identityServerConfig.AllowedScopes,
|
AllowedScopes = identityServerConfiguration.AllowedScopes,
|
||||||
SupportedTokens = SupportedTokens.Both,
|
SupportedTokens = SupportedTokens.Both,
|
||||||
ApiSecret = identityServerConfig.ApiSecret
|
ApiSecret = identityServerConfiguration.ApiSecret
|
||||||
});
|
});
|
||||||
|
|
||||||
app.UseIdentityServer();
|
app.UseIdentityServer();
|
||||||
@ -182,7 +198,6 @@ namespace Ocelot.Middleware
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void UseIfNotNull(this IApplicationBuilder builder, Func<HttpContext, Func<Task>, Task> middleware)
|
private static void UseIfNotNull(this IApplicationBuilder builder, Func<HttpContext, Func<Task>, Task> middleware)
|
||||||
{
|
{
|
||||||
if (middleware != null)
|
if (middleware != null)
|
||||||
|
@ -11,6 +11,7 @@ using CacheManager.Core;
|
|||||||
using Microsoft.AspNetCore.Hosting;
|
using Microsoft.AspNetCore.Hosting;
|
||||||
using Microsoft.AspNetCore.TestHost;
|
using Microsoft.AspNetCore.TestHost;
|
||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using Ocelot.Configuration.File;
|
using Ocelot.Configuration.File;
|
||||||
@ -32,6 +33,7 @@ namespace Ocelot.AcceptanceTests
|
|||||||
public HttpClient OcelotClient => _ocelotClient;
|
public HttpClient OcelotClient => _ocelotClient;
|
||||||
public string RequestIdKey = "OcRequestId";
|
public string RequestIdKey = "OcRequestId";
|
||||||
private readonly Random _random;
|
private readonly Random _random;
|
||||||
|
private IWebHostBuilder _webHostBuilder;
|
||||||
|
|
||||||
public Steps()
|
public Steps()
|
||||||
{
|
{
|
||||||
@ -69,7 +71,14 @@ namespace Ocelot.AcceptanceTests
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public void GivenOcelotIsRunning()
|
public void GivenOcelotIsRunning()
|
||||||
{
|
{
|
||||||
_ocelotServer = new TestServer(new WebHostBuilder()
|
_webHostBuilder = new WebHostBuilder();
|
||||||
|
|
||||||
|
_webHostBuilder.ConfigureServices(s =>
|
||||||
|
{
|
||||||
|
s.AddSingleton(_webHostBuilder);
|
||||||
|
});
|
||||||
|
|
||||||
|
_ocelotServer = new TestServer(_webHostBuilder
|
||||||
.UseStartup<Startup>());
|
.UseStartup<Startup>());
|
||||||
|
|
||||||
_ocelotClient = _ocelotServer.CreateClient();
|
_ocelotClient = _ocelotServer.CreateClient();
|
||||||
@ -109,7 +118,14 @@ namespace Ocelot.AcceptanceTests
|
|||||||
|
|
||||||
var configuration = builder.Build();
|
var configuration = builder.Build();
|
||||||
|
|
||||||
_ocelotServer = new TestServer(new WebHostBuilder()
|
_webHostBuilder = new WebHostBuilder();
|
||||||
|
|
||||||
|
_webHostBuilder.ConfigureServices(s =>
|
||||||
|
{
|
||||||
|
s.AddSingleton(_webHostBuilder);
|
||||||
|
});
|
||||||
|
|
||||||
|
_ocelotServer = new TestServer(_webHostBuilder
|
||||||
.UseConfiguration(configuration)
|
.UseConfiguration(configuration)
|
||||||
.ConfigureServices(s =>
|
.ConfigureServices(s =>
|
||||||
{
|
{
|
||||||
@ -121,7 +137,7 @@ namespace Ocelot.AcceptanceTests
|
|||||||
})
|
})
|
||||||
.WithDictionaryHandle();
|
.WithDictionaryHandle();
|
||||||
};
|
};
|
||||||
|
|
||||||
s.AddOcelotOutputCaching(settings);
|
s.AddOcelotOutputCaching(settings);
|
||||||
s.AddOcelotFileConfiguration(configuration);
|
s.AddOcelotFileConfiguration(configuration);
|
||||||
s.AddOcelot();
|
s.AddOcelot();
|
||||||
|
@ -5,6 +5,7 @@ using System.Net;
|
|||||||
using System.Net.Http;
|
using System.Net.Http;
|
||||||
using System.Net.Http.Headers;
|
using System.Net.Http.Headers;
|
||||||
using Microsoft.AspNetCore.Hosting;
|
using Microsoft.AspNetCore.Hosting;
|
||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using Ocelot.Configuration.File;
|
using Ocelot.Configuration.File;
|
||||||
using Ocelot.ManualTest;
|
using Ocelot.ManualTest;
|
||||||
@ -19,6 +20,7 @@ namespace Ocelot.IntegrationTests
|
|||||||
private readonly HttpClient _httpClient;
|
private readonly HttpClient _httpClient;
|
||||||
private HttpResponseMessage _response;
|
private HttpResponseMessage _response;
|
||||||
private IWebHost _builder;
|
private IWebHost _builder;
|
||||||
|
private IWebHostBuilder _webHostBuilder;
|
||||||
private readonly string _ocelotBaseUrl;
|
private readonly string _ocelotBaseUrl;
|
||||||
private BearerToken _token;
|
private BearerToken _token;
|
||||||
|
|
||||||
@ -246,12 +248,16 @@ namespace Ocelot.IntegrationTests
|
|||||||
|
|
||||||
private void GivenOcelotIsRunning()
|
private void GivenOcelotIsRunning()
|
||||||
{
|
{
|
||||||
_builder = new WebHostBuilder()
|
_webHostBuilder = new WebHostBuilder()
|
||||||
.UseUrls(_ocelotBaseUrl)
|
.UseUrls(_ocelotBaseUrl)
|
||||||
.UseKestrel()
|
.UseKestrel()
|
||||||
.UseContentRoot(Directory.GetCurrentDirectory())
|
.UseContentRoot(Directory.GetCurrentDirectory())
|
||||||
.UseStartup<Startup>()
|
.ConfigureServices(x => {
|
||||||
.Build();
|
x.AddSingleton(_webHostBuilder);
|
||||||
|
})
|
||||||
|
.UseStartup<Startup>();
|
||||||
|
|
||||||
|
_builder = _webHostBuilder.Build();
|
||||||
|
|
||||||
_builder.Start();
|
_builder.Start();
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
using System.IO;
|
using System.IO;
|
||||||
using Microsoft.AspNetCore.Hosting;
|
using Microsoft.AspNetCore.Hosting;
|
||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
|
||||||
namespace Ocelot.ManualTest
|
namespace Ocelot.ManualTest
|
||||||
{
|
{
|
||||||
@ -7,11 +8,17 @@ namespace Ocelot.ManualTest
|
|||||||
{
|
{
|
||||||
public static void Main(string[] args)
|
public static void Main(string[] args)
|
||||||
{
|
{
|
||||||
var host = new WebHostBuilder()
|
IWebHostBuilder builder = new WebHostBuilder();
|
||||||
.UseKestrel()
|
|
||||||
|
builder.ConfigureServices(s => {
|
||||||
|
s.AddSingleton(builder);
|
||||||
|
});
|
||||||
|
|
||||||
|
builder.UseKestrel()
|
||||||
.UseContentRoot(Directory.GetCurrentDirectory())
|
.UseContentRoot(Directory.GetCurrentDirectory())
|
||||||
.UseStartup<Startup>()
|
.UseStartup<Startup>();
|
||||||
.Build();
|
|
||||||
|
var host = builder.Build();
|
||||||
|
|
||||||
host.Run();
|
host.Run();
|
||||||
}
|
}
|
||||||
|
@ -6,6 +6,7 @@ using Microsoft.AspNetCore.Hosting;
|
|||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
|
using Ocelot.Configuration.Provider;
|
||||||
using Ocelot.DependencyInjection;
|
using Ocelot.DependencyInjection;
|
||||||
using Ocelot.Middleware;
|
using Ocelot.Middleware;
|
||||||
using ConfigurationBuilder = Microsoft.Extensions.Configuration.ConfigurationBuilder;
|
using ConfigurationBuilder = Microsoft.Extensions.Configuration.ConfigurationBuilder;
|
||||||
@ -14,6 +15,8 @@ namespace Ocelot.ManualTest
|
|||||||
{
|
{
|
||||||
public class Startup
|
public class Startup
|
||||||
{
|
{
|
||||||
|
private IdentityServerConfiguration _identityServerConfig;
|
||||||
|
|
||||||
public Startup(IHostingEnvironment env)
|
public Startup(IHostingEnvironment env)
|
||||||
{
|
{
|
||||||
var builder = new ConfigurationBuilder()
|
var builder = new ConfigurationBuilder()
|
||||||
@ -24,6 +27,9 @@ namespace Ocelot.ManualTest
|
|||||||
.AddEnvironmentVariables();
|
.AddEnvironmentVariables();
|
||||||
|
|
||||||
Configuration = builder.Build();
|
Configuration = builder.Build();
|
||||||
|
|
||||||
|
var identityServerConfigProvider = new HardCodedIdentityServerConfigurationProvider();
|
||||||
|
_identityServerConfig = identityServerConfigProvider.Get();
|
||||||
}
|
}
|
||||||
|
|
||||||
public IConfigurationRoot Configuration { get; }
|
public IConfigurationRoot Configuration { get; }
|
||||||
@ -41,14 +47,14 @@ namespace Ocelot.ManualTest
|
|||||||
|
|
||||||
services.AddOcelotOutputCaching(settings);
|
services.AddOcelotOutputCaching(settings);
|
||||||
services.AddOcelotFileConfiguration(Configuration);
|
services.AddOcelotFileConfiguration(Configuration);
|
||||||
services.AddOcelot();
|
services.AddOcelot(_identityServerConfig);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
|
public async void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
|
||||||
{
|
{
|
||||||
loggerFactory.AddConsole(Configuration.GetSection("Logging"));
|
loggerFactory.AddConsole(Configuration.GetSection("Logging"));
|
||||||
|
|
||||||
await app.UseOcelot();
|
await app.UseOcelot(_identityServerConfig);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user