I have a Keycloak v26 setup with a single realm that contains:
10 users, all of whom currently have access to all clients.
2 clients: client1 and client2.
I want to restrict login access so that only specific users can log in to specific clients.
I saw that I could use authorization but I am using browser login, not client credentials. Authorization exists only for client credentials flow, which I am not using. I need a way to enforce access control during the login process.
So
User A should be able to log in to client1 but not client2.
User B should be able to log in to client2 but not client1.
User C should have access to both clients.
Users without the required permissions should be denied login.
How can I enforce this restriction in Keycloak v26 during browser login?
I have a Keycloak v26 setup with a single realm that contains:
10 users, all of whom currently have access to all clients.
2 clients: client1 and client2.
I want to restrict login access so that only specific users can log in to specific clients.
I saw that I could use authorization but I am using browser login, not client credentials. Authorization exists only for client credentials flow, which I am not using. I need a way to enforce access control during the login process.
So
User A should be able to log in to client1 but not client2.
User B should be able to log in to client2 but not client1.
User C should have access to both clients.
Users without the required permissions should be denied login.
How can I enforce this restriction in Keycloak v26 during browser login?
Share Improve this question asked Mar 25 at 10:48 Ayodeji ErinfolamiAyodeji Erinfolami 4402 silver badges12 bronze badges1 Answer
Reset to default 1To enforce client-specific login restrictions in Keycloak v26 for browser-based logins (e.g., OIDC Authorization Code Flow), you can use client-level role-based access control combined with authorization policies. Here's how to configure this:
Step 1: Create Client-Specific Roles
For client1:
Go to
Clients
→ Select client1 →
Roles
→
Add Role
.
Create a role named client1_access (or similar).
For client2:
Repeat the process, creating a role named client2_access.
Step 2: Assign Roles to Users
User A:
Go to Users → Select User A → Role Mappings.
Assign the client1_access role under client1.
User B:
Assign the client2_access role under client2.
User C:
Assign both client1_access and client2_access roles.
Step 3: Enable Authorization for Clients
Keycloak’s Authorization Services work for browser logins too. Configure it for each client:
For client1:
Go to Clients → client1 → Authorization → Settings.
Enable Authorization.
Under Authorization Scopes, add a scope (e.g., login).
Repeat for client2.
Step 4: Create Authorization Policies
Policy for client1:
Go to Authorization → Policies → Create.
Policy Type: Role.
Name: client1_access_policy.
Roles: Select client1_access (from the client1 dropdown).
Logic: Positive.
Policy for client2:
Repeat the process for client2_access.
Step 5: Create Authorization Permissions
Permission for client1:
Go to Authorization → Permissions → Create.
Name: client1_login_permission.
Resource Type: Select the login scope (created earlier).
Apply Policy: Select client1_access_policy.
Decision Strategy: Unanimous.
Permission for client2:
Repeat for client2.
Step 6: Test the Setup
User A logs into client1: Allowed.
User A logs into client2: Denied (no client2_access role).
User C logs into both clients: Allowed.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744202494a4562947.html
评论列表(0条)