diff --git a/README.md b/README.md index 9bbaf309..5745ee79 100644 --- a/README.md +++ b/README.md @@ -42,7 +42,7 @@ ReRoutes: UpstreamTemplate: / UpstreamHttpMethod: Post AuthenticationOptions: - Provider: IdentityServer.AccessToken + Provider: IdentityServer ProviderRootUrl: http://localhost:51888 ScopeName: api AdditionalScopes: [] diff --git a/src/Ocelot.Library/Configuration/Yaml/YamlReRoute.cs b/src/Ocelot.Library/Configuration/Yaml/YamlReRoute.cs index 0b7be040..ed3410b5 100644 --- a/src/Ocelot.Library/Configuration/Yaml/YamlReRoute.cs +++ b/src/Ocelot.Library/Configuration/Yaml/YamlReRoute.cs @@ -1,10 +1,18 @@ namespace Ocelot.Library.Configuration.Yaml { + using System.Collections.Generic; + public class YamlReRoute { + public YamlReRoute() + { + AddHeadersToRequest = new Dictionary(); + } + public string DownstreamTemplate { get; set; } public string UpstreamTemplate { get; set; } public string UpstreamHttpMethod { get; set; } public YamlAuthenticationOptions AuthenticationOptions { get; set; } + public Dictionary AddHeadersToRequest { get; set; } } } \ No newline at end of file diff --git a/test/Ocelot.AcceptanceTests/AuthenticationTests.cs b/test/Ocelot.AcceptanceTests/AuthenticationTests.cs index 8994e77c..c962b47b 100644 --- a/test/Ocelot.AcceptanceTests/AuthenticationTests.cs +++ b/test/Ocelot.AcceptanceTests/AuthenticationTests.cs @@ -144,6 +144,47 @@ namespace Ocelot.AcceptanceTests .BDDfy(); } + [Fact] + public void should_return_response_200_and_foward_claim_as_header() + { + + this.Given(x => x.GivenThereIsAnIdentityServerOn("http://localhost:51888", "api", AccessTokenType.Jwt)) + .And(x => x.GivenThereIsAServiceRunningOn("http://localhost:51876", 200, "Hello from Laura")) + .And(x => x.GivenIHaveAToken("http://localhost:51888")) + .And(x => x.GivenThereIsAConfiguration(new YamlConfiguration + { + ReRoutes = new List + { + new YamlReRoute + { + DownstreamTemplate = "http://localhost:51876/", + UpstreamTemplate = "/", + UpstreamHttpMethod = "Get", + AuthenticationOptions = new YamlAuthenticationOptions + { + AdditionalScopes = new List(), + Provider = "IdentityServer", + ProviderRootUrl = "http://localhost:51888", + RequireHttps = false, + ScopeName = "api", + ScopeSecret = "secret" + }, + AddHeadersToRequest = + { + { "CustomerId","Claims[CustomerId] > long" }, + { "LocationId","Claims[LocationId] > int" } + } + } + } + })) + .And(x => x.GivenTheApiGatewayIsRunning()) + .And(x => x.GivenIHaveAddedATokenToMyRequest()) + .When(x => x.WhenIGetUrlOnTheApiGateway("/")) + .Then(x => x.ThenTheStatusCodeShouldBe(HttpStatusCode.OK)) + .And(x => x.ThenTheResponseBodyShouldBe("Hello from Laura")) + .BDDfy(); + } + [Fact] public void should_return_201_using_identity_server_access_token() { diff --git a/test/Ocelot.AcceptanceTests/OcelotTests.cs b/test/Ocelot.AcceptanceTests/OcelotTests.cs index 8caf3e17..b838736b 100644 --- a/test/Ocelot.AcceptanceTests/OcelotTests.cs +++ b/test/Ocelot.AcceptanceTests/OcelotTests.cs @@ -55,7 +55,7 @@ namespace Ocelot.AcceptanceTests { DownstreamTemplate = "http://localhost:51879/", UpstreamTemplate = "/", - UpstreamHttpMethod = "Get" + UpstreamHttpMethod = "Get", } } })) diff --git a/test/Ocelot.AcceptanceTests/configuration.yaml b/test/Ocelot.AcceptanceTests/configuration.yaml index c438428b..29e93d20 100644 --- a/test/Ocelot.AcceptanceTests/configuration.yaml +++ b/test/Ocelot.AcceptanceTests/configuration.yaml @@ -1,5 +1,13 @@ ReRoutes: -- DownstreamTemplate: http://localhost:51879/ +- DownstreamTemplate: http://localhost:51876/ UpstreamTemplate: / - UpstreamHttpMethod: Get - Authentication: IdentityServer.AccessToken + UpstreamHttpMethod: Post + AuthenticationOptions: + Provider: IdentityServer + ProviderRootUrl: http://localhost:51888 + ScopeName: api + AdditionalScopes: [] + ScopeSecret: secret + ProxyRequestHeaders: + - CustomerId: Claims[CustomerId] +