Skip to content

Commit 9fa4da1

Browse files
committed
feat(keycloak) add keycloak guide
1 parent df5fc6c commit 9fa4da1

14 files changed

+264
-0
lines changed
Lines changed: 264 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,264 @@
1+
2+
---
3+
slug: configure-keycloak-sso
4+
title: "Using Keycloak as an Identity Provider"
5+
description: "This article shows how to configure Keycloak as an Identity Provider (IdP) for Pydio Cells, including client setup, attribute mapping, and common troubleshooting."
6+
language: und
7+
category: Identity Management
8+
weight: 2
9+
tags:
10+
- sso
11+
- keycloak
12+
- mapping
13+
---
14+
15+
# Introduction
16+
17+
**Keycloak** is a robust, open-source Identity and Access Management (IAM) tool that implements popular SSO standards like **SAML** and **OpenID Connect (OIDC)**.
18+
It’s widely trusted for secure authentication in on-premise deployments, enabling organizations to centralize user identity and integrate easily with various services.
19+
20+
This step-by-step guide will help you:
21+
- Register a new OIDC client in Keycloak.
22+
- Set up an OIDC Connector in **Pydio Cells**.
23+
- Map user attributes from Keycloak (using LDAP directory) to user roles in Pydio Cells.
24+
- Understand how to fix session-related issues and debug your configuration.
25+
26+
27+
## S1. Register a New OIDC Client in Keycloak
28+
29+
To enable SSO, first register a new client that represents Pydio Cells in your Keycloak instance.
30+
31+
> **Tip:** Steps 1 and 2 can be done in parallel — you’ll need the Connector’s `callback URL` for the client’s redirect URI.
32+
>
33+
> **Note:** This example uses the `master` realm.
34+
35+
**Keycloak Admin Console:**
36+
```
37+
Clients → Create Client
38+
```
39+
40+
![](../images/connectors/keycloak/create-new-client.png)
41+
42+
**Example values:**
43+
- **Client ID:** `demo.cells.pydio`
44+
- **Name:** `Cells Demo`
45+
46+
![](../images/connectors/keycloak/keycloak-new-client-0.png)
47+
48+
49+
**Configure redirect and URLs:**
50+
- **Root URL:** Pydio Cells URL
51+
- **Home URL:** Same as above
52+
- **Valid Redirect URIs:** Callback URL generated by the Connector in Step 2
53+
- **Valid Post Logout Redirect URIs:** Leave empty
54+
- **Web Origins:** Pydio Cells URL
55+
56+
![](../images/connectors/keycloak/keycloak-create-client-3.png)
57+
58+
59+
60+
**New Client Capability:**
61+
- **Cells Authentication:** Yes
62+
- **Authorization:** Off
63+
- **Authentication Flow:** Standard
64+
65+
![](../images/connectors/keycloak/keycloak-new-client-2.png)
66+
67+
### Client Credentials
68+
69+
Enabling `Cells Authentication` generates a **Client Secret**. Pydio Cells uses this secret to securely authenticate with Keycloak’s OIDC endpoints.
70+
71+
![](../images/connectors/keycloak/keycloak-new-client-secret.png)
72+
73+
74+
75+
## S2. Create a New Connector in Pydio Cells
76+
77+
Inside Pydio Cells, create a new OIDC Connector to link your Cells instance to Keycloak.
78+
79+
**Cells Admin Console:**
80+
```
81+
Settings → Authentication → OAUTH2/OIDC → Create New Connector
82+
```
83+
84+
In the pop-up:
85+
- **Connector type:** OpenID Connect
86+
- **ID:** `keycloak` (won't be changed)
87+
- **Name:** Example: `SSO with Keycloak` (can be customized later)
88+
89+
The **Issuer (Canonical URL)** updates automatically based on the ID. This URL acts as the callback where Keycloak sends tokens after authentication.
90+
91+
![](../images/connectors/keycloak/cells-new-connector-2.png)
92+
93+
Pause here, return to **Step 1**, and add the generated callback URL to the client’s valid redirect URIs in Keycloak.
94+
95+
96+
### Complete the Connector Configuration
97+
98+
Once you have your **Client ID** and **Client Secret**, continue filling out:
99+
100+
- **Issuer - Canonical URL:**
101+
Format: `https://domain/realms/realm-name`
102+
Example: `https://sso.keycloak.pydio/realms/master`
103+
104+
- **Client ID:** The client ID from Step 1 (`demo.cells.pydio`)
105+
- **Client Secret:** Copied from Keycloak.
106+
107+
![](../images/connectors/keycloak/cells-new-connector-3.png)
108+
109+
**Additional options:**
110+
- **Insecure Skip Email Verified:** Set `On` if using a trusted directory.
111+
- **Get User Info:** On
112+
113+
![](../images/connectors/keycloak/cells-new-connector-4.png)
114+
115+
Once saved, your Pydio Cells login page will display an additional **“SSO with Keycloak”** option.
116+
117+
# Advanced Setup
118+
119+
A key feature of Pydio Cells is the ability to map external attributes to automatically manage user roles.
120+
This is powerful when you want to sync LDAP groups directly to Cells permissions.
121+
122+
123+
## Mapping Roles
124+
125+
Suppose your Keycloak server uses an LDAP User Federation and you want to map the `memberOf` LDAP attribute to Pydio Cells roles.
126+
127+
### 1. Map LDAP User to UserModel in Keycloak
128+
129+
**Keycloak Admin Console:**
130+
```
131+
User Federation → Select LDAP Provider → Mappers → Create Mapper
132+
```
133+
134+
Example mapper:
135+
- **Name:** `memberOf to group`
136+
- **Mapper type:** `user-attribute-ldap-mapper`
137+
- **User Model Attribute:** `cellsgroups`
138+
- **LDAP Attribute:** `memberOf`
139+
- **Read Only:** On
140+
- **Always Read Value From LDAP:** On
141+
142+
![](../images/connectors/keycloak/keycloak-ldap-memberof-mapping.png)
143+
144+
145+
### 2. Create a Client Scope and Mapper
146+
147+
**Keycloak Admin Console:**
148+
```
149+
Client Scopes → Create Client Scope
150+
```
151+
152+
- **Name:** `cellsscope`
153+
- **Description:** Defines `cellsgroups` claim
154+
155+
![](../images/connectors/keycloak/keycloak-client-scope-settings.png)
156+
157+
Add a new mapper in the scope:
158+
- **Mapper Type:** User Attribute
159+
- **Name:** User Group Mapper
160+
- **User Attribute:** `cellsgroups`
161+
- **Token Claim Name:** `cellsgroups`
162+
- **Claim JSON Type:** string
163+
- **Add to ID Token:** On
164+
- **Add to Access Token:** On
165+
- **Add to Userinfo:** On
166+
- **MultiValued:** On
167+
- **Aggregate attribute values:** On
168+
169+
![](../images/connectors/keycloak/keycloak-mapping-usermodel-attribute-to-claim.png)
170+
171+
> **Note:** The *UserModel* is the user object in Keycloak.
172+
173+
174+
### 3. Example ID Token
175+
176+
When the user logs in through Keycloak, the ID Token will look like this:
177+
178+
```json
179+
{
180+
"Claims": {
181+
"cellsgroups": [
182+
"cn=Test_DEM_WebUsers,ou=test-pydio-cells,...",
183+
"cn=Test_Etrange_Gov,ou=test-pydio-cells,...",
184+
"cn=Test_GitlabDTC,pydio-cells,..."
185+
],
186+
...
187+
}
188+
}
189+
```
190+
191+
192+
### 4. Map ID Token Claims to Cells Roles
193+
194+
In the Cells Connector configuration, click `+ ADD RULE`:
195+
196+
- **Left Attribute:** `cellsgroups`
197+
- **Right Attribute:** `Roles`
198+
199+
![](../images/connectors/keycloak/cells-mapping-roles.png)
200+
201+
Now, users logging in with Keycloak SSO will automatically have these roles assigned in Pydio Cells.
202+
203+
204+
# Additional Configuration
205+
206+
Sometimes you may experience unexpected session logouts for SSO users, while local auth sessions remain stable.
207+
This is often due to a missing **`audience` claim** in the token, which is required for token validation.
208+
209+
## The Root Cause
210+
211+
- After authentication, the client gets an **AccessToken** and **RefreshToken**.
212+
- By default, the AccessToken expires in ~10 minutes. Near expiry, the client tries to refresh it.
213+
- If the token is missing an `audience` claim, the refresh request fails, resulting in a forced logout.
214+
215+
216+
## How to Test
217+
218+
1. Open Chrome Dev Tools.
219+
2. Upload a large file to Cells.
220+
3. Use throttling to simulate a slow network.
221+
4. Wait until the AccessToken expires (~10 minutes).
222+
223+
Watch for `session` requests — if a refresh fails with a `401`, you’ll see the session close.
224+
225+
226+
## Solutions
227+
228+
### 1. Add Audience in Config
229+
230+
Run the following command:
231+
232+
```bash
233+
cells admin config set "pydio.web.oauth" "staticClients[0]/audience[0]" "https://demo.cells.pydio"
234+
```
235+
236+
### 2. Or Edit `pydio.json` Directly
237+
238+
```json
239+
"pydio.web.oauth": {
240+
"staticClients": [
241+
{
242+
"audience": [
243+
"https://demo.cells.pydio"
244+
]
245+
}
246+
]
247+
}
248+
```
249+
250+
251+
# Troubleshooting
252+
253+
## Run Cells in Debug Mode
254+
255+
Because there are multiple moving parts between Keycloak and Pydio Cells, start Cells in **debug mode** to:
256+
257+
- See detailed error messages.
258+
- Inspect full ID Tokens sent by Keycloak.
259+
- Verify your claim mappings.
260+
261+
## Keep Server Clocks in Sync
262+
263+
Authentication can fail if server and client clocks are out of sync.
264+
Always configure **automatic time synchronization** on both the Keycloak and Cells servers, as well as user devices, to prevent unexpected token validation errors.
167 KB
Loading
216 KB
Loading
234 KB
Loading
221 KB
Loading
145 KB
Loading
125 KB
Loading
144 KB
Loading
142 KB
Loading
110 KB
Loading

0 commit comments

Comments
 (0)