started working on stripping claims from token

This commit is contained in:
tom.pallister 2016-10-17 20:46:30 +01:00
parent 3d60602c7e
commit 2395736b6b
5 changed files with 62 additions and 5 deletions

View File

@ -42,7 +42,7 @@ ReRoutes:
UpstreamTemplate: /
UpstreamHttpMethod: Post
AuthenticationOptions:
Provider: IdentityServer.AccessToken
Provider: IdentityServer
ProviderRootUrl: http://localhost:51888
ScopeName: api
AdditionalScopes: []

View File

@ -1,10 +1,18 @@
namespace Ocelot.Library.Configuration.Yaml
{
using System.Collections.Generic;
public class YamlReRoute
{
public YamlReRoute()
{
AddHeadersToRequest = new Dictionary<string, string>();
}
public string DownstreamTemplate { get; set; }
public string UpstreamTemplate { get; set; }
public string UpstreamHttpMethod { get; set; }
public YamlAuthenticationOptions AuthenticationOptions { get; set; }
public Dictionary<string,string> AddHeadersToRequest { get; set; }
}
}

View File

@ -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<YamlReRoute>
{
new YamlReRoute
{
DownstreamTemplate = "http://localhost:51876/",
UpstreamTemplate = "/",
UpstreamHttpMethod = "Get",
AuthenticationOptions = new YamlAuthenticationOptions
{
AdditionalScopes = new List<string>(),
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()
{

View File

@ -55,7 +55,7 @@ namespace Ocelot.AcceptanceTests
{
DownstreamTemplate = "http://localhost:51879/",
UpstreamTemplate = "/",
UpstreamHttpMethod = "Get"
UpstreamHttpMethod = "Get",
}
}
}))

View File

@ -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]