Multiple values for single key in RouteClaimsRequirement
See original GitHub issueNew Feature
Allow claims to have an array value and not just a string value.
Motivation for New Feature
I have an application where I have multiple roles for my users. For endpoints that should only be reached by admins, I can use the following:
"RouteClaimsRequirement": {
"Role": "Admin"
}
For endpoints that should only be reached by users, I can use the following:
"RouteClaimsRequirement": {
"Role": "User"
}
For endpoints that should be reached by both users and admins I would like to use the following:
"RouteClaimsRequirement": {
"Role": ["User", "Admin"]
}
When I tried adding this, all requests to the endpoint respond with a 404.
This should let the request go through if the request has a claim for the role user or admin. This is equivalent to the built-in asp .net core attribute:
[Authorize(Roles = "User, Admin")]
Issue Analytics
- State:
- Created 5 years ago
- Reactions:13
- Comments:21 (3 by maintainers)
Top Results From Across the Web
Multiple values for single key in RouteClaimsRequirement
Allow claims to have an array value and not just a string value.
Read more >Handling the multiple values for single key in the API URL
I need to handle the multiple values for the single key in the URL. Ex: values/{values} => values/1,2,3. I refered the following URL:...
Read more >[Solved]-Multiple values for single key-LINQ,C#
My colleague and I realized that we can keep track of the Category's and if same Category occurs, it means that only a...
Read more >How to include multiple values on a key? And then iterate?
The lesson has conveyed that keys can have multiple values. 1) How would multiple values be created, for instance, in this exercise?
Read more >Building your own ASP.Net Core API gateway with Ocelot
I am facing one issue with ocelot. Error logging is enabled in the gateway project.I can see only a message ocelot request key...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I’ve tried the override authorisation middleware method , but the claims are strictly converted in a Dictionary<string,string> format before the middleware was called ;
This format break the Route because the value cannot be converted into a string;
This format also don’t work because the Role key in dictionary will be ovverride with the second value;
so… My personal solution will be Workaround example
In the authorisation middleware method , i will parse the string with a regex pattern to obtain the single role value:
The logic of Authorize Method
remeber to add in the ConfigureService method
(I Still working on my Authorization logic that will implement the multiple claims with And/Or logic with regex of strings , but the claims data structure implemented with Dictionary<string , string> is very ugly and not very flexible)
//updated for last version of ocelot
by using @arro000 's trick I changed a few things to make it work for me on .Net Core 3.1 & Ocelot 16.0.1. My answer on Stackoverflow. https://stackoverflow.com/questions/60300349/how-to-check-claim-value-in-array-or-any-in-ocelot-gateway/62390542#62390542