ThreeMammals/Ocelot

Ocelot doesn't handle correctly RouteClaimsRequirement with a key as an Url

Aperta

#679 aperta il 7 nov 2018

 (22 commenti) (9 reazioni) (1 assegnatario)C# (1617 fork)batch import
AuthorizationSpring'26Summer'26buggood first issuehelp wantedmedium effortproposal

Metriche repository

Star
 (8137 stelle)
Metriche merge PR
 (Merge medio 44g 17h) (6 PR mergiate in 30 g)

Descrizione

While creating JWT for a user in my authentication service I use System.Security.Claims.ClaimTypes static class with defined string constants for various claims. So, ClaimTypes.Role == "http://schemas.microsoft.com/ws/2008/06/identity/claims/role":

var claims = new List<Claim>
{
    new Claim("ID", user.Id.ToString()),
    new Claim(ClaimTypes.Name, user.Username)
};
claims.AddRange(user.Roles.Select(role => new Claim(ClaimTypes.Role, role)));

Then, when for some Route in RouteClaimsRequirement I write: "http://schemas.microsoft.com/ws/2008/06/identity/claims/role" : "Admin"

"RouteClaimsRequirement": {
        "http://schemas.microsoft.com/ws/2008/06/identity/claims/role": "Admin"
}

Such Route just disappears somewhere in the guts of middleware (I didn't manage to track down where this happens) and a request results in 404 because a route is not found:

Error Code: UnableToFindDownstreamRouteError Message: Unable to find downstream route for path: /api/entities/, verb: POST errors found in ResponderMiddleware. Setting error response for request path:/api/entities/, request method: POST

When I use my own claim type like "Role", this works fine. So I assume there are some issues with (de)serialization of a string containing colons or slashes, basically as any URL.

Specifications

  • Version: 12.0.1 - 19.0.2

Guida contributor