mirror of
https://github.com/nsnail/Ocelot.git
synced 2025-04-23 00:32:50 +08:00
moved stuff around so a bit less crap
This commit is contained in:
parent
112a9c303e
commit
07c334cc98
@ -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,17 +54,14 @@ 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<FileConfiguration>(configurationRoot);
|
||||
services.AddSingleton<IOcelotConfigurationCreator, FileOcelotConfigurationCreator>();
|
||||
services.AddSingleton<IOcelotConfigurationRepository, InMemoryOcelotConfigurationRepository>();
|
||||
services.AddSingleton<IConfigurationValidator, FileConfigurationValidator>();
|
||||
|
||||
var identityServerConfiguration = GetIdentityServerConfiguration();
|
||||
|
||||
if(identityServerConfiguration != null)
|
||||
{
|
||||
services.AddSingleton<IIdentityServerConfiguration>(identityServerConfiguration);
|
||||
@ -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<string> {"admin", "openid", "offline_access"},
|
||||
"Ocelot Administration",
|
||||
true,
|
||||
GrantTypes.ResourceOwnerPassword,
|
||||
AccessTokenType.Jwt,
|
||||
false,
|
||||
new List<User>
|
||||
{
|
||||
new User("admin", username, hash, salt)
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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<string> {"admin", "openid", "offline_access"},
|
||||
"Ocelot Administration",
|
||||
true,
|
||||
GrantTypes.ResourceOwnerPassword,
|
||||
AccessTokenType.Jwt,
|
||||
false,
|
||||
new List<User>
|
||||
{
|
||||
new User("admin", username, hash, salt)
|
||||
}
|
||||
);
|
||||
|
||||
services.AddOcelot(Configuration, _identityServerConfig);
|
||||
services.AddOcelot(Configuration);
|
||||
}
|
||||
|
||||
public async void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
|
||||
|
Loading…
x
Reference in New Issue
Block a user