ThreeMammals/Ocelot

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

Ouverte

#679 ouverte le 7 nov. 2018

 (22 commentaires) (9 réactions) (1 personne assignée)C# (1 617 forks)batch import
AuthorizationSpring'26Summer'26buggood first issuehelp wantedmedium effortproposal

Métriques du dépôt

Stars
 (8 137 étoiles)
Métriques de merge PR
 (Merge moyen 44j 17h) (6 PRs mergées en 30 j)

Description

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

Guide contributeur