mirror of
https://github.com/nsnail/Ocelot.git
synced 2025-04-22 06:22:50 +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.Builder;
|
||||||
using Ocelot.Configuration.File;
|
using Ocelot.Configuration.File;
|
||||||
|
using Ocelot.Creator.Configuration;
|
||||||
|
|
||||||
namespace Ocelot.Configuration.Creator
|
namespace Ocelot.Configuration.Creator
|
||||||
{
|
{
|
||||||
public class AuthenticationOptionsCreator : IAuthenticationOptionsCreator
|
public class AuthenticationOptionsCreator : IAuthenticationOptionsCreator
|
||||||
{
|
{
|
||||||
|
private readonly IAuthenticationProviderConfigCreator _creator;
|
||||||
|
|
||||||
|
public AuthenticationOptionsCreator(IAuthenticationProviderConfigCreator creator)
|
||||||
|
{
|
||||||
|
_creator = creator;
|
||||||
|
}
|
||||||
|
|
||||||
public AuthenticationOptions Create(FileReRoute fileReRoute)
|
public AuthenticationOptions Create(FileReRoute fileReRoute)
|
||||||
{
|
{
|
||||||
var authenticationConfig = new ConfigCreator().Create(fileReRoute.AuthenticationOptions);
|
var authenticationConfig = _creator.Create(fileReRoute.AuthenticationOptions);
|
||||||
|
|
||||||
return new AuthenticationOptionsBuilder()
|
return new AuthenticationOptionsBuilder()
|
||||||
.WithProvider(fileReRoute.AuthenticationOptions?.Provider)
|
.WithProvider(fileReRoute.AuthenticationOptions?.Provider)
|
||||||
|
@ -1,13 +1,15 @@
|
|||||||
|
using Ocelot.Creator.Configuration;
|
||||||
|
|
||||||
namespace Ocelot.Configuration.Creator
|
namespace Ocelot.Configuration.Creator
|
||||||
{
|
{
|
||||||
using Ocelot.Configuration.Builder;
|
using Ocelot.Configuration.Builder;
|
||||||
using Ocelot.Configuration.File;
|
using Ocelot.Configuration.File;
|
||||||
|
|
||||||
public class ConfigCreator
|
public class AuthenticationProviderConfigCreator : IAuthenticationProviderConfigCreator
|
||||||
{
|
{
|
||||||
public IAuthenticationConfig Create(FileAuthenticationOptions authenticationOptions)
|
public IAuthenticationConfig Create(FileAuthenticationOptions authenticationOptions)
|
||||||
{
|
{
|
||||||
if (authenticationOptions.Provider == "Jwt")
|
if (authenticationOptions.Provider?.ToLower() == "jwt")
|
||||||
{
|
{
|
||||||
return CreateJwt(authenticationOptions);
|
return CreateJwt(authenticationOptions);
|
||||||
}
|
}
|
@ -31,13 +31,13 @@ namespace Ocelot.Configuration.Creator
|
|||||||
private readonly IQosProviderHouse _qosProviderHouse;
|
private readonly IQosProviderHouse _qosProviderHouse;
|
||||||
private readonly IClaimsToThingCreator _claimsToThingCreator;
|
private readonly IClaimsToThingCreator _claimsToThingCreator;
|
||||||
private readonly IAuthenticationOptionsCreator _authOptionsCreator;
|
private readonly IAuthenticationOptionsCreator _authOptionsCreator;
|
||||||
private IUpstreamTemplatePatternCreator _upstreamTemplatePatternCreator;
|
private readonly IUpstreamTemplatePatternCreator _upstreamTemplatePatternCreator;
|
||||||
private IRequestIdKeyCreator _requestIdKeyCreator;
|
private readonly IRequestIdKeyCreator _requestIdKeyCreator;
|
||||||
private IServiceProviderConfigurationCreator _serviceProviderConfigCreator;
|
private readonly IServiceProviderConfigurationCreator _serviceProviderConfigCreator;
|
||||||
private IQoSOptionsCreator _qosOptionsCreator;
|
private readonly IQoSOptionsCreator _qosOptionsCreator;
|
||||||
private IReRouteOptionsCreator _fileReRouteOptionsCreator;
|
private readonly IReRouteOptionsCreator _fileReRouteOptionsCreator;
|
||||||
private IRateLimitOptionsCreator _rateLimitOptionsCreator;
|
private readonly IRateLimitOptionsCreator _rateLimitOptionsCreator;
|
||||||
private IRegionCreator _regionCreator;
|
private readonly IRegionCreator _regionCreator;
|
||||||
|
|
||||||
public FileOcelotConfigurationCreator(
|
public FileOcelotConfigurationCreator(
|
||||||
IOptions<FileConfiguration> options,
|
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 System.Security.Cryptography.X509Certificates;
|
||||||
using Microsoft.IdentityModel.Tokens;
|
using Microsoft.IdentityModel.Tokens;
|
||||||
using Ocelot.Configuration;
|
using Ocelot.Configuration;
|
||||||
|
using Ocelot.Creator.Configuration;
|
||||||
using FileConfigurationProvider = Ocelot.Configuration.Provider.FileConfigurationProvider;
|
using FileConfigurationProvider = Ocelot.Configuration.Provider.FileConfigurationProvider;
|
||||||
|
|
||||||
namespace Ocelot.DependencyInjection
|
namespace Ocelot.DependencyInjection
|
||||||
@ -71,6 +72,7 @@ namespace Ocelot.DependencyInjection
|
|||||||
|
|
||||||
services.Configure<FileConfiguration>(configurationRoot);
|
services.Configure<FileConfiguration>(configurationRoot);
|
||||||
services.TryAddSingleton<IOcelotConfigurationCreator, FileOcelotConfigurationCreator>();
|
services.TryAddSingleton<IOcelotConfigurationCreator, FileOcelotConfigurationCreator>();
|
||||||
|
services.TryAddSingleton<IAuthenticationProviderConfigCreator, AuthenticationProviderConfigCreator>();
|
||||||
services.TryAddSingleton<IOcelotConfigurationRepository, InMemoryOcelotConfigurationRepository>();
|
services.TryAddSingleton<IOcelotConfigurationRepository, InMemoryOcelotConfigurationRepository>();
|
||||||
services.TryAddSingleton<IConfigurationValidator, FileConfigurationValidator>();
|
services.TryAddSingleton<IConfigurationValidator, FileConfigurationValidator>();
|
||||||
services.TryAddSingleton<IBaseUrlFinder, BaseUrlFinder>();
|
services.TryAddSingleton<IBaseUrlFinder, BaseUrlFinder>();
|
||||||
|
@ -14,13 +14,16 @@
|
|||||||
},
|
},
|
||||||
"AuthenticationOptions": {
|
"AuthenticationOptions": {
|
||||||
"Provider": "IdentityServer",
|
"Provider": "IdentityServer",
|
||||||
"ProviderRootUrl": "http://localhost:52888",
|
|
||||||
"ApiName": "api",
|
|
||||||
"AllowedScopes": [
|
"AllowedScopes": [
|
||||||
"openid",
|
"openid",
|
||||||
"offline_access"
|
"offline_access"
|
||||||
],
|
],
|
||||||
"ApiSecret": "secret"
|
"IdentityServerConfig": {
|
||||||
|
"ProviderRootUrl": "http://localhost:52888",
|
||||||
|
"ApiName": "api",
|
||||||
|
"ApiSecret": "secret",
|
||||||
|
"RequireHttps": false
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"AddHeadersToRequest": {
|
"AddHeadersToRequest": {
|
||||||
"CustomerId": "Claims[CustomerId] > value",
|
"CustomerId": "Claims[CustomerId] > value",
|
||||||
|
@ -11,13 +11,13 @@ namespace Ocelot.UnitTests.Configuration
|
|||||||
{
|
{
|
||||||
public class AuthenticationOptionsCreatorTests
|
public class AuthenticationOptionsCreatorTests
|
||||||
{
|
{
|
||||||
private AuthenticationOptionsCreator _authOptionsCreator;
|
private readonly AuthenticationOptionsCreator _authOptionsCreator;
|
||||||
private FileReRoute _fileReRoute;
|
private FileReRoute _fileReRoute;
|
||||||
private AuthenticationOptions _result;
|
private AuthenticationOptions _result;
|
||||||
|
|
||||||
public AuthenticationOptionsCreatorTests()
|
public AuthenticationOptionsCreatorTests()
|
||||||
{
|
{
|
||||||
_authOptionsCreator = new AuthenticationOptionsCreator();
|
_authOptionsCreator = new AuthenticationOptionsCreator(new AuthenticationProviderConfigCreator());
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user