This repository was archived by the owner on Mar 25, 2021. It is now read-only.
Open
Conversation
Collaborator
|
We might have to think about this one. There could be the possibility that you could end up having duplicate roles. For example if you had this jwt: "realm-management": {
"roles": [
"realm-admin"
]
},
"myapp": {
"roles": [
"realm-admin"
]
}
The ClaimsPricipal roles would look like this: 1. http://schemas.microsoft.com/ws/2008/06/identity/claims/role: realm-admin 2. http://schemas.microsoft.com/ws/2008/06/identity/claims/role: realm-admin` As an alternate appraoch to your code above,we do pass back the access_token in the Claims, so you can simply get this information currently by decoding the jwt like this: var me = User as ClaimsPrincipal; string token = me.Claims.FirstOrDefault(c => c.Type == "access_token").Value; JwtSecurityToken tokenParsed = new JwtSecurityToken(token); var globalRoles = tokenParsed.Claims.Where(c => c.Type == "resource_access"); |
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
I have some global realm roles, see JWT excerpt below. I found that Keycloak Owin did not map them. This is the code I needed to add to make it working.
Both types of roles are mapped to
ClaimTypes.Role. This works for me, but I don't know if there is a better possibility to do this.Best regards,
Alexander