can now use tokens from ocelot a on ocelot b when using admin area

This commit is contained in:
Tom Gardham-Pallister 2017-06-23 15:17:40 +01:00
parent 2d94884c6f
commit 6cdf4e67df
8 changed files with 29 additions and 7 deletions

1
.gitignore vendored
View File

@ -183,6 +183,7 @@ ClientBin/
*.dbmdl *.dbmdl
*.dbproj.schemaview *.dbproj.schemaview
*.pfx *.pfx
!idsrv3test.pfx
*.publishsettings *.publishsettings
node_modules/ node_modules/
orleans.codegen.cs orleans.codegen.cs

View File

@ -89,7 +89,10 @@ namespace Ocelot.DependencyInjection
{ {
services.TryAddSingleton<IIdentityServerConfiguration>(identityServerConfiguration); services.TryAddSingleton<IIdentityServerConfiguration>(identityServerConfiguration);
services.TryAddSingleton<IHashMatcher, HashMatcher>(); services.TryAddSingleton<IHashMatcher, HashMatcher>();
var identityServerBuilder = services.AddIdentityServer() var identityServerBuilder = services
.AddIdentityServer(options => {
options.IssuerUri = "Ocelot";
})
.AddInMemoryApiResources(new List<ApiResource> .AddInMemoryApiResources(new List<ApiResource>
{ {
new ApiResource new ApiResource

View File

@ -181,7 +181,6 @@ 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 app.UseIdentityServerAuthentication(new IdentityServerAuthenticationOptions
{ {
Authority = identityServerUrl, Authority = identityServerUrl,

View File

@ -15,7 +15,7 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<None Update="configuration.json;idsrv3test.pfx"> <None Update="configuration.json;appsettings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None> </None>
</ItemGroup> </ItemGroup>

View File

@ -0,0 +1,10 @@
{
"Logging": {
"IncludeScopes": true,
"LogLevel": {
"Default": "Error",
"System": "Error",
"Microsoft": "Error"
}
}
}

View File

@ -86,9 +86,9 @@ namespace Ocelot.IntegrationTests
}; };
this.Given(x => GivenThereIsAConfiguration(configuration)) this.Given(x => GivenThereIsAConfiguration(configuration))
.And(x => GivenIdentityServerSigningEnvironmentalVariablesAreSet())
.And(x => GivenOcelotIsRunning()) .And(x => GivenOcelotIsRunning())
.And(x => GivenIHaveAnOcelotToken("/administration")) .And(x => GivenIHaveAnOcelotToken("/administration"))
.And(x => GivenIHaveAddedATokenToMyRequest())
.And(x => GivenAnotherOcelotIsRunning("http://localhost:5007")) .And(x => GivenAnotherOcelotIsRunning("http://localhost:5007"))
.When(x => WhenIGetUrlOnTheSecondOcelot("/administration/configuration")) .When(x => WhenIGetUrlOnTheSecondOcelot("/administration/configuration"))
.Then(x => ThenTheStatusCodeShouldBe(HttpStatusCode.OK)) .Then(x => ThenTheStatusCodeShouldBe(HttpStatusCode.OK))
@ -227,7 +227,7 @@ namespace Ocelot.IntegrationTests
.UseKestrel() .UseKestrel()
.UseContentRoot(Directory.GetCurrentDirectory()) .UseContentRoot(Directory.GetCurrentDirectory())
.ConfigureServices(x => { .ConfigureServices(x => {
x.AddSingleton(_webHostBuilder); x.AddSingleton(_webHostBuilderTwo);
}) })
.UseStartup<Startup>(); .UseStartup<Startup>();
@ -236,8 +236,15 @@ namespace Ocelot.IntegrationTests
_builderTwo.Start(); _builderTwo.Start();
} }
private void GivenIdentityServerSigningEnvironmentalVariablesAreSet()
{
Environment.SetEnvironmentVariable("OCELOT_CERTIFICATE", "idsrv3test.pfx");
Environment.SetEnvironmentVariable("OCELOT_CERTIFICATE_PASSWORD", "idsrv3test");
}
private void WhenIGetUrlOnTheSecondOcelot(string url) private void WhenIGetUrlOnTheSecondOcelot(string url)
{ {
_httpClientTwo.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", _token.AccessToken);
_response = _httpClientTwo.GetAsync(url).Result; _response = _httpClientTwo.GetAsync(url).Result;
} }
@ -353,6 +360,8 @@ namespace Ocelot.IntegrationTests
public void Dispose() public void Dispose()
{ {
Environment.SetEnvironmentVariable("OCELOT_CERTIFICATE", "");
Environment.SetEnvironmentVariable("OCELOT_CERTIFICATE_PASSWORD", "");
_builder?.Dispose(); _builder?.Dispose();
_httpClient?.Dispose(); _httpClient?.Dispose();
} }

View File

@ -3,8 +3,8 @@
"IncludeScopes": true, "IncludeScopes": true,
"LogLevel": { "LogLevel": {
"Default": "Error", "Default": "Error",
"System": "Information", "System": "Error",
"Microsoft": "Information" "Microsoft": "Error"
} }
} }
} }

Binary file not shown.