mirror of
https://github.com/nsnail/Ocelot.git
synced 2025-04-22 14:02:49 +08:00
bit more tidying
This commit is contained in:
parent
34cd2e1392
commit
09c9a25883
@ -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)
|
||||
|
@ -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);
|
||||
}
|
@ -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<FileConfiguration> options,
|
||||
|
@ -0,0 +1,10 @@
|
||||
using Ocelot.Configuration;
|
||||
using Ocelot.Configuration.File;
|
||||
|
||||
namespace Ocelot.Creator.Configuration
|
||||
{
|
||||
public interface IAuthenticationProviderConfigCreator
|
||||
{
|
||||
IAuthenticationConfig Create(FileAuthenticationOptions authenticationOptions);
|
||||
}
|
||||
}
|
@ -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<FileConfiguration>(configurationRoot);
|
||||
services.TryAddSingleton<IOcelotConfigurationCreator, FileOcelotConfigurationCreator>();
|
||||
services.TryAddSingleton<IAuthenticationProviderConfigCreator, AuthenticationProviderConfigCreator>();
|
||||
services.TryAddSingleton<IOcelotConfigurationRepository, InMemoryOcelotConfigurationRepository>();
|
||||
services.TryAddSingleton<IConfigurationValidator, FileConfigurationValidator>();
|
||||
services.TryAddSingleton<IBaseUrlFinder, BaseUrlFinder>();
|
||||
|
@ -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",
|
||||
|
@ -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]
|
||||
|
Loading…
x
Reference in New Issue
Block a user