[New feature] Support claims to path transformation#968
Merged
thiagoloureiro merged 2 commits intoThreeMammals:developfrom Aug 12, 2019
Merged
[New feature] Support claims to path transformation#968thiagoloureiro merged 2 commits intoThreeMammals:developfrom
thiagoloureiro merged 2 commits intoThreeMammals:developfrom
Conversation
Contributor
Author
|
any update on this? it has sense to merge, do you thing it is useful? |
|
Hi, thanks for adding this functionality, we need exactly this in our project. Do you have any idea when this will be merged in and released? |
Contributor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add the option to transform a claim to the downstream path. Similar to the Claims To Query String forwarding. We are starting to use Ocelot in our backend and we need this feature, to transform the user id from the claims to the downstream backend. This way we can do things like this:
/api/users/me(defined only in the API gateway)/api/users/{userId}(defined in the users microservice backend)The request contains the
user_idin the claims, so it can then change the downstream path with theuser_idto the users microservice backend/api/users/{userId}Proposed Changes
ChangeDownstreamPathTemplatesubstitutes the placeholder that matches theClaimToThingexisting key.An example usage
ocelot.json:{ "UpstreamPathTemplate": "/api/users/me", "DownstreamHostAndPorts": [ { "Host": "localhost", "Port": 63048 } ], "DownstreamPathTemplate": "/api/users/{userId}", "DownstreamScheme": "http", "AuthenticationOptions": { "AuthenticationProviderKey": "AuthJWTKey", "AllowedScopes": [] }, "ChangeDownstreamPathTemplate": { "userId": "Claims[user_id] > value" } }if the
DownstreamPathTemplatecontains a placeholder that matchesChangeDownstreamPathTemplateexisting key (in the exampleuserId) it substitutes the value so will end up calling the downstream host with/api/users/123.if
ChangeDownstreamPathTemplatecontains a claim to things, but there is no match in theDownstreamPathTemplateit will respond with an error.The middleware basically adds or changes a
PlaceholderNameAndValuefrom theDownstreamContext.TemplatePlaceholderNameAndValues, so when theDownstreamUrlCreatorMiddlewareexecutes it will replace the placeholder with the values from the claims.