Skip to content

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

@dmitriifilonenko

Description

@dmitriifilonenko

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

Metadata

Metadata

Labels

AuthorizationOcelot feature: AuthorizationSummer'25Summer 2025 releasebugIdentified as a potential bugmedium effortLikely a few days of development effortneeds validationIssue has not been replicated or verified yetproposalProposal for a new functionality in Ocelot

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions