Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ability to access all roles of multiple keycloak clients in a OpenID token #23138

Closed
Markus-Schwer opened this issue Jan 24, 2022 · 2 comments
Closed

Comments

@Markus-Schwer
Copy link
Contributor

Description

This might be a niche use-case, but I need to check if a user has a specific role from another client.
As an example, suppose I have a keycloak OpenID token with two roles from two clients:

{
  "name": "John Doe",
  ...
  "resource_access": {
     "client1": {
        "roles": [
           "role1"
        ]
     },
     "client2": {
        "roles": [
           "role2"
        ]
     }
  }
}

My oidc config in my application.properties looks something like this:

quarkus.oidc.auth-server-url=://localhost:8180/auth/realms/quarkus
quarkus.oidc.client-id=client1
# the role-claim-path is implicitly resource_access/ + clientId + /roles
# quarkus.oidc.roles.role-claim-path=resource_access/client1/roles

In my application code I need to check if the user/token has both role1 and role2. Currently this does not work, as the quarkus.oidc.roles.role-claim-path can only select a single claim, and keycloak tokens have different claims for multiple clients.

Implementation ideas

Idea 1

The config property quarkus.oidc.roles.role-claim-path could be refactored to accept a list of claim paths, e.g.:

quarkus.oidc.roles.role-claim-path=resource_access/client1/roles,resource_access/client2/roles

Idea 2

Another idea would be to allow wildcards in the quarkus.oidc.roles.role-claim-path property:

quarkus.oidc.roles.role-claim-path=resource_access/*/roles

The second idea might be more usefull, when a token has a lot of different clients and you don't want to list every client in your configuration. Also, the wildcard approach would be more similar to other keycloak oidc implementations, like the keycloak-wildfyl-adapter, where (as far as I can remember) you can access all roles from a token.

@Markus-Schwer Markus-Schwer added the kind/enhancement New feature or request label Jan 24, 2022
@quarkus-bot
Copy link

quarkus-bot bot commented Jan 24, 2022

/cc @pedroigor, @sberyozkin

@Markus-Schwer Markus-Schwer changed the title Ability to access all roles of all keycloak clients in a OpenID token Ability to access all roles of multiple keycloak clients in a OpenID token Jan 24, 2022
@sberyozkin
Copy link
Member

#23139 Fixes it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants