How can i restrict client access to only one group of users in keycloak?

后端 未结 8 615
一生所求
一生所求 2020-12-24 15:08

I have a client in keycloak for my awx(ansible tower) webpage. I need only the users from one specific keycloak group to be able to log in through

相关标签:
8条回答
  • 2020-12-24 15:35

    You can use this extension to restrict access to a specific group: https://github.com/thomasdarimont/keycloak-extension-playground/tree/master/auth-require-group-extension

    0 讨论(0)
  • 2020-12-24 15:39

    I found a solution which does not require the scripts extension or any changes on the flow.

    The key for this solution are the Client Scopes. An application which wants to to authorize a user needs a scope like email or uid, right? What if you only pass them to an application if a user is in a specific group?

    In the following, my client application name is App1.

    Solution:

    1. Go to your client roles (realm -> Clients -> click App1 -> Roles)
    2. Click 'Add Role' -> enter Name (e.g. 'access') -> click 'Save'
    3. Go to Client Scopes (realm -> Client Scopes)
    4. Click on the scope which is needed by your client application (e.g. 'email')
    5. Assign Client Role 'access' in 'Scope' Tab by choosing client application 'App1' in Drop Down 'Client Roles'

    Now, you won't be able to log into your client application App1 anymore, as the role 'access' is not assigned to any user or group. You can try.

    Let's create a new group and assign the role and a user to it.

    1. Create Group (realm -> Groups -> Click 'New' -> enter Name 'App1 Users' -> Click Save)
    2. In the Group, choose 'Role Mappings', choose 'App1' in Client Roles drop down, and assign the role 'access'
    3. Assign User to 'App1 Users' (realm -> Users -> Click on User -> Groups -> Select 'App1 Users -> Click Join)

    Voila, the chosen user can log into App1.

    0 讨论(0)
提交回复
热议问题