mirror of
https://github.com/nsnail/Ocelot.git
synced 2025-04-22 06:22:50 +08:00
unit tests pass...
This commit is contained in:
parent
1c98dcbca3
commit
6419919e74
@ -18,24 +18,25 @@ namespace Ocelot.Authentication.Handler.Creator
|
|||||||
{
|
{
|
||||||
public Response<RequestDelegate> Create(IApplicationBuilder app, AuthenticationOptions authOptions)
|
public Response<RequestDelegate> Create(IApplicationBuilder app, AuthenticationOptions authOptions)
|
||||||
{
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
var builder = app.New();
|
var builder = app.New();
|
||||||
|
|
||||||
if (authOptions.Provider.ToLower() == "jwt")
|
if (authOptions.Provider.ToLower() == "jwt")
|
||||||
{
|
{
|
||||||
var authenticationConfig = authOptions.Config as JwtConfig;
|
var authenticationConfig = authOptions.Config as JwtConfig;
|
||||||
|
|
||||||
builder.UseJwtBearerAuthentication(
|
/* builder.UseJwtBearerAuthentication(
|
||||||
new JwtBearerOptions()
|
new JwtBearerOptions()
|
||||||
{
|
{
|
||||||
Authority = authenticationConfig.Authority,
|
Authority = authenticationConfig.Authority,
|
||||||
Audience = authenticationConfig.Audience
|
Audience = authenticationConfig.Audience
|
||||||
});
|
});*/
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
var authenticationConfig = authOptions.Config as IdentityServerConfig;
|
var authenticationConfig = authOptions.Config as IdentityServerConfig;
|
||||||
|
|
||||||
builder.UseIdentityServerAuthentication(new IdentityServerAuthenticationOptions
|
/* builder.UseIdentityServerAuthentication(new IdentityServerAuthenticationOptions
|
||||||
{
|
{
|
||||||
Authority = authenticationConfig.ProviderRootUrl,
|
Authority = authenticationConfig.ProviderRootUrl,
|
||||||
ApiName = authenticationConfig.ApiName,
|
ApiName = authenticationConfig.ApiName,
|
||||||
@ -43,7 +44,7 @@ namespace Ocelot.Authentication.Handler.Creator
|
|||||||
AllowedScopes = authOptions.AllowedScopes,
|
AllowedScopes = authOptions.AllowedScopes,
|
||||||
SupportedTokens = SupportedTokens.Both,
|
SupportedTokens = SupportedTokens.Both,
|
||||||
ApiSecret = authenticationConfig.ApiSecret
|
ApiSecret = authenticationConfig.ApiSecret
|
||||||
});
|
});*/
|
||||||
}
|
}
|
||||||
|
|
||||||
var authenticationNext = builder.Build();
|
var authenticationNext = builder.Build();
|
||||||
|
@ -129,7 +129,7 @@ namespace Ocelot.DependencyInjection
|
|||||||
|
|
||||||
if (string.IsNullOrEmpty(identityServerConfiguration.CredentialsSigningCertificateLocation) || string.IsNullOrEmpty(identityServerConfiguration.CredentialsSigningCertificatePassword))
|
if (string.IsNullOrEmpty(identityServerConfiguration.CredentialsSigningCertificateLocation) || string.IsNullOrEmpty(identityServerConfiguration.CredentialsSigningCertificatePassword))
|
||||||
{
|
{
|
||||||
identityServerBuilder.AddTemporarySigningCredential();
|
identityServerBuilder.AddDeveloperSigningCredential();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using IdentityServer4.AccessTokenValidation;
|
using IdentityServer4.AccessTokenValidation;
|
||||||
using Microsoft.AspNetCore.Builder;
|
using Microsoft.AspNetCore.Builder;
|
||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using Ocelot.Authentication.Middleware;
|
using Ocelot.Authentication.Middleware;
|
||||||
using Ocelot.Cache.Middleware;
|
using Ocelot.Cache.Middleware;
|
||||||
using Ocelot.Claims.Middleware;
|
using Ocelot.Claims.Middleware;
|
||||||
@ -38,9 +39,9 @@ namespace Ocelot.Middleware
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="builder"></param>
|
/// <param name="builder"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static async Task<IApplicationBuilder> UseOcelot(this IApplicationBuilder builder)
|
public static async Task<IApplicationBuilder> UseOcelot(this IApplicationBuilder builder, IServiceCollection services)
|
||||||
{
|
{
|
||||||
await builder.UseOcelot(new OcelotMiddlewareConfiguration());
|
await builder.UseOcelot(new OcelotMiddlewareConfiguration(), services);
|
||||||
|
|
||||||
return builder;
|
return builder;
|
||||||
}
|
}
|
||||||
@ -51,9 +52,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, IServiceCollection services)
|
||||||
{
|
{
|
||||||
await CreateAdministrationArea(builder);
|
await CreateAdministrationArea(builder, services);
|
||||||
|
|
||||||
ConfigureDiagnosticListener(builder);
|
ConfigureDiagnosticListener(builder);
|
||||||
|
|
||||||
@ -170,7 +171,7 @@ namespace Ocelot.Middleware
|
|||||||
return ocelotConfiguration.Data;
|
return ocelotConfiguration.Data;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static async Task CreateAdministrationArea(IApplicationBuilder builder)
|
private static async Task CreateAdministrationArea(IApplicationBuilder builder, IServiceCollection services)
|
||||||
{
|
{
|
||||||
var configuration = await CreateConfiguration(builder);
|
var configuration = await CreateConfiguration(builder);
|
||||||
|
|
||||||
@ -185,18 +186,20 @@ namespace Ocelot.Middleware
|
|||||||
builder.Map(configuration.AdministrationPath, app =>
|
builder.Map(configuration.AdministrationPath, app =>
|
||||||
{
|
{
|
||||||
var identityServerUrl = $"{baseSchemeUrlAndPort}/{configuration.AdministrationPath.Remove(0,1)}";
|
var identityServerUrl = $"{baseSchemeUrlAndPort}/{configuration.AdministrationPath.Remove(0,1)}";
|
||||||
app.UseIdentityServerAuthentication(new IdentityServerAuthenticationOptions
|
|
||||||
|
services.AddAuthentication(IdentityServerAuthenticationDefaults.AuthenticationScheme)
|
||||||
|
.AddIdentityServerAuthentication(o =>
|
||||||
{
|
{
|
||||||
Authority = identityServerUrl,
|
o.Authority = identityServerUrl;
|
||||||
ApiName = identityServerConfiguration.ApiName,
|
o.ApiName = identityServerConfiguration.ApiName;
|
||||||
RequireHttpsMetadata = identityServerConfiguration.RequireHttps,
|
o.RequireHttpsMetadata = identityServerConfiguration.RequireHttps;
|
||||||
AllowedScopes = identityServerConfiguration.AllowedScopes,
|
o.AllowedScopes = identityServerConfiguration.AllowedScopes;
|
||||||
SupportedTokens = SupportedTokens.Both,
|
o.SupportedTokens = SupportedTokens.Both;
|
||||||
ApiSecret = identityServerConfiguration.ApiSecret
|
o.ApiSecret = identityServerConfiguration.ApiSecret;
|
||||||
});
|
});
|
||||||
|
|
||||||
app.UseIdentityServer();
|
app.UseIdentityServer();
|
||||||
|
app.UseAuthentication();
|
||||||
app.UseMvc();
|
app.UseMvc();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<OutputType>Exe</OutputType>
|
|
||||||
<TargetFramework>netcoreapp2.0</TargetFramework>
|
<TargetFramework>netcoreapp2.0</TargetFramework>
|
||||||
<RuntimeFrameworkVersion>2.0.0</RuntimeFrameworkVersion>
|
<RuntimeFrameworkVersion>2.0.0</RuntimeFrameworkVersion>
|
||||||
|
<NETStandardImplicitPackageVersion>2.0.0</NETStandardImplicitPackageVersion>
|
||||||
<Description>This project is aimed at people using .NET running a micro services / service orientated architecture that need a unified point of entry into their system. In particular I want easy integration with IdentityServer reference and bearer tokens. We have been unable to find this in my current workplace without having to write our own Javascript middlewares to handle the IdentityServer reference tokens. We would rather use the IdentityServer code that already exists to do this. Ocelot is a bunch of middlewares in a specific order. Ocelot manipulates the HttpRequest object into a state specified by its configuration until it reaches a request builder middleware where it creates a HttpRequestMessage object which is used to make a request to a downstream service. The middleware that makes the request is the last thing in the Ocelot pipeline. It does not call the next middleware. The response from the downstream service is stored in a per request scoped repository and retrived as the requests goes back up the Ocelot pipeline. There is a piece of middleware that maps the HttpResponseMessage onto the HttpResponse object and that is returned to the client. That is basically it with a bunch of other features.</Description>
|
<Description>This project is aimed at people using .NET running a micro services / service orientated architecture that need a unified point of entry into their system. In particular I want easy integration with IdentityServer reference and bearer tokens. We have been unable to find this in my current workplace without having to write our own Javascript middlewares to handle the IdentityServer reference tokens. We would rather use the IdentityServer code that already exists to do this. Ocelot is a bunch of middlewares in a specific order. Ocelot manipulates the HttpRequest object into a state specified by its configuration until it reaches a request builder middleware where it creates a HttpRequestMessage object which is used to make a request to a downstream service. The middleware that makes the request is the last thing in the Ocelot pipeline. It does not call the next middleware. The response from the downstream service is stored in a per request scoped repository and retrived as the requests goes back up the Ocelot pipeline. There is a piece of middleware that maps the HttpResponseMessage onto the HttpResponse object and that is returned to the client. That is basically it with a bunch of other features.</Description>
|
||||||
<AssemblyTitle>Ocelot</AssemblyTitle>
|
<AssemblyTitle>Ocelot</AssemblyTitle>
|
||||||
<VersionPrefix>0.0.0-dev</VersionPrefix>
|
<VersionPrefix>0.0.0-dev</VersionPrefix>
|
||||||
|
@ -275,7 +275,7 @@ namespace Ocelot.AcceptanceTests
|
|||||||
{
|
{
|
||||||
services.AddLogging();
|
services.AddLogging();
|
||||||
services.AddIdentityServer()
|
services.AddIdentityServer()
|
||||||
.AddTemporarySigningCredential()
|
.AddDeveloperSigningCredential()
|
||||||
.AddInMemoryApiResources(new List<ApiResource>
|
.AddInMemoryApiResources(new List<ApiResource>
|
||||||
{
|
{
|
||||||
new ApiResource
|
new ApiResource
|
||||||
|
@ -259,7 +259,7 @@ namespace Ocelot.AcceptanceTests
|
|||||||
{
|
{
|
||||||
services.AddLogging();
|
services.AddLogging();
|
||||||
services.AddIdentityServer()
|
services.AddIdentityServer()
|
||||||
.AddTemporarySigningCredential()
|
.AddDeveloperSigningCredential()
|
||||||
.AddInMemoryApiResources(new List<ApiResource>
|
.AddInMemoryApiResources(new List<ApiResource>
|
||||||
{
|
{
|
||||||
new ApiResource
|
new ApiResource
|
||||||
|
@ -133,7 +133,7 @@ namespace Ocelot.AcceptanceTests
|
|||||||
{
|
{
|
||||||
services.AddLogging();
|
services.AddLogging();
|
||||||
services.AddIdentityServer()
|
services.AddIdentityServer()
|
||||||
.AddTemporarySigningCredential()
|
.AddDeveloperSigningCredential()
|
||||||
.AddInMemoryApiResources(new List<ApiResource>
|
.AddInMemoryApiResources(new List<ApiResource>
|
||||||
{
|
{
|
||||||
new ApiResource
|
new ApiResource
|
||||||
|
@ -140,7 +140,7 @@ namespace Ocelot.AcceptanceTests
|
|||||||
{
|
{
|
||||||
services.AddLogging();
|
services.AddLogging();
|
||||||
services.AddIdentityServer()
|
services.AddIdentityServer()
|
||||||
.AddTemporarySigningCredential()
|
.AddDeveloperSigningCredential()
|
||||||
.AddInMemoryApiResources(new List<ApiResource>
|
.AddInMemoryApiResources(new List<ApiResource>
|
||||||
{
|
{
|
||||||
new ApiResource
|
new ApiResource
|
||||||
|
@ -31,6 +31,7 @@
|
|||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.0" />
|
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.0" />
|
||||||
|
<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="2.0.0" />
|
||||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.3.0" />
|
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.3.0" />
|
||||||
<PackageReference Include="xunit.runner.visualstudio" Version="2.3.0-beta2-build1317" />
|
<PackageReference Include="xunit.runner.visualstudio" Version="2.3.0-beta2-build1317" />
|
||||||
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="2.0.0" />
|
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="2.0.0" />
|
||||||
|
@ -134,6 +134,7 @@ namespace Ocelot.AcceptanceTests
|
|||||||
.AddJsonFile("configuration.json")
|
.AddJsonFile("configuration.json")
|
||||||
.AddEnvironmentVariables();
|
.AddEnvironmentVariables();
|
||||||
|
|
||||||
|
IServiceCollection serviceCollection = new ServiceCollection();
|
||||||
var configuration = builder.Build();
|
var configuration = builder.Build();
|
||||||
|
|
||||||
_webHostBuilder = new WebHostBuilder();
|
_webHostBuilder = new WebHostBuilder();
|
||||||
@ -157,15 +158,16 @@ namespace Ocelot.AcceptanceTests
|
|||||||
};
|
};
|
||||||
|
|
||||||
s.AddOcelot(configuration, settings);
|
s.AddOcelot(configuration, settings);
|
||||||
|
serviceCollection = s;
|
||||||
})
|
})
|
||||||
.ConfigureLogging(l =>
|
.ConfigureLogging(l =>
|
||||||
{
|
{
|
||||||
l.AddConsole(configuration.GetSection("Logging"));
|
l.AddConsole();
|
||||||
l.AddDebug();
|
l.AddDebug();
|
||||||
})
|
})
|
||||||
.Configure(a =>
|
.Configure(a =>
|
||||||
{
|
{
|
||||||
a.UseOcelot(ocelotMiddlewareConfig).Wait();
|
a.UseOcelot(ocelotMiddlewareConfig, serviceCollection).Wait();
|
||||||
}));
|
}));
|
||||||
|
|
||||||
_ocelotClient = _ocelotServer.CreateClient();
|
_ocelotClient = _ocelotServer.CreateClient();
|
||||||
|
@ -26,6 +26,7 @@ namespace Ocelot.ManualTest
|
|||||||
}
|
}
|
||||||
|
|
||||||
public IConfigurationRoot Configuration { get; }
|
public IConfigurationRoot Configuration { get; }
|
||||||
|
public IServiceCollection Services { get; private set; }
|
||||||
|
|
||||||
public void ConfigureServices(IServiceCollection services)
|
public void ConfigureServices(IServiceCollection services)
|
||||||
{
|
{
|
||||||
@ -39,13 +40,14 @@ namespace Ocelot.ManualTest
|
|||||||
};
|
};
|
||||||
|
|
||||||
services.AddOcelot(Configuration, settings);
|
services.AddOcelot(Configuration, settings);
|
||||||
|
Services = services;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
|
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
|
||||||
{
|
{
|
||||||
loggerFactory.AddConsole(Configuration.GetSection("Logging"));
|
loggerFactory.AddConsole(Configuration.GetSection("Logging"));
|
||||||
|
|
||||||
app.UseOcelot().Wait();
|
app.UseOcelot(Services).Wait();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -33,6 +33,7 @@
|
|||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.0" />
|
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.0" />
|
||||||
|
<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="2.0.0" />
|
||||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.3.0" />
|
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.3.0" />
|
||||||
<PackageReference Include="xunit.runner.visualstudio" Version="2.3.0-beta2-build1317" />
|
<PackageReference Include="xunit.runner.visualstudio" Version="2.3.0-beta2-build1317" />
|
||||||
<PackageReference Include="Microsoft.DotNet.InternalAbstractions" Version="1.0.0" />
|
<PackageReference Include="Microsoft.DotNet.InternalAbstractions" Version="1.0.0" />
|
||||||
|
Loading…
x
Reference in New Issue
Block a user