mirror of
https://github.com/nsnail/Ocelot.git
synced 2025-06-17 18:23:21 +08:00
can now use tokens from ocelot a on ocelot b when using admin area
This commit is contained in:
parent
2d94884c6f
commit
6cdf4e67df
1
.gitignore
vendored
1
.gitignore
vendored
@ -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
|
||||||
|
@ -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
|
||||||
|
@ -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,
|
||||||
|
@ -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>
|
||||||
|
10
test/Ocelot.AcceptanceTests/appsettings.json
Normal file
10
test/Ocelot.AcceptanceTests/appsettings.json
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
{
|
||||||
|
"Logging": {
|
||||||
|
"IncludeScopes": true,
|
||||||
|
"LogLevel": {
|
||||||
|
"Default": "Error",
|
||||||
|
"System": "Error",
|
||||||
|
"Microsoft": "Error"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -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();
|
||||||
}
|
}
|
||||||
|
@ -3,8 +3,8 @@
|
|||||||
"IncludeScopes": true,
|
"IncludeScopes": true,
|
||||||
"LogLevel": {
|
"LogLevel": {
|
||||||
"Default": "Error",
|
"Default": "Error",
|
||||||
"System": "Information",
|
"System": "Error",
|
||||||
"Microsoft": "Information"
|
"Microsoft": "Error"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
BIN
test/Ocelot.IntegrationTests/idsrv3test.pfx
Normal file
BIN
test/Ocelot.IntegrationTests/idsrv3test.pfx
Normal file
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user