How Decidim single sign-on with Keycloak through OmniAuth works
A public body or civil society group that already runs Keycloak can let participants sign in to Decidim with the same accounts, and Decidim makes this possible without a separate login system. Decidim supports Facebook, Twitter, Google and Decidim-to-Decidim OAuth 2.0 out of the box, and any other OmniAuth strategy can be added as a custom provider. Keycloak speaks OpenID Connect, OAuth 2.0 and SAML 2.0, so the work is to connect Decidim's OmniAuth layer to a Keycloak client that your identity team controls. The provider is configured per organization, which matters for multi-tenant installations where each city, department or assembly may need its own identity settings.
The exact provider configuration must be confirmed against the Decidim social providers documentation for the target version, because the names of settings, callback paths and provider options can change between the 0.31.x and 0.32.x lines. This page assumes a self-hosted Decidim 0.32.x or 0.31.x and a Keycloak instance that the client operates. Before writing any code, confirm which Keycloak realm, client and redirect URIs the participant-facing organization will use, and who in your organization approves changes to them. Those decisions shape everything that follows, from attribute mapping to the registration rules that determine whether a Keycloak login creates a Decidim account automatically.
The sections that follow cover the build sequence, the decisions behind each setting, and how to verify the result. The most important early decision is whether Keycloak sign-in is one option among several or the only way to register and log in. That choice determines how much your identity team depends on Decidim being available and how participants recover access when Keycloak is unavailable, so settle it with the governance owner of the platform before the first configuration change.
What you need before configuring Keycloak for Decidim
Decidim single sign-on with Keycloak depends on a Decidim release, a runtime stack, a Keycloak line and database, and named ownership for each organization's sign-in settings. Settle these choices first, because a mismatch in any of them is hard to unpick once participants start signing in.
Decidim release and runtime
Pick the Decidim minor version you will run and match its runtime exactly. Version 0.32 requires Ruby 3.4.7 and Node 22.14.x, while 0.31 uses Ruby 3.3.4 and Node 22.14.x. Only the last two minor branches receive security updates before version 1.0, so confirm that the branch you choose is still supported when you go live.
Manual installation guidePostgreSQL and Ubuntu baselines
The manual installation guide uses PostgreSQL 17.4 or later on Ubuntu 24.04.3 LTS. Use those as your reference baseline and confirm them against the guide for your chosen Decidim version. Record the operating system and database versions in your build inventory so that upgrades to Decidim can be tested against the same stack.
Decidim installation docsKeycloak release line to maintain
Choose a Keycloak release line your team will keep current. The current upstream release is 26.8.1. Red Hat build of Keycloak is a supported distribution option based on the same project, and Red Hat's product page showed 26.6 as its latest version. Keycloak plans four minor releases a year, so agree who applies them and how often.
Keycloak docsProduction database for Keycloak
Keycloak's dev-file database is for development only. For production, pick a database from its supported list, such as PostgreSQL 14 to 18, MySQL, MariaDB, Oracle Database, Microsoft SQL Server or a managed option like Amazon Aurora PostgreSQL. Confirm backup, restore and failover for that database before you connect Decidim's sign-in flow to it.
Keycloak database guideDNS name and TLS certificate per organization
Each Decidim organization needs its own host name and a valid TLS certificate, because OmniAuth callbacks and redirect URIs are built from that host. Keycloak's client redirect URIs must match these exact addresses. Plan certificate renewal and the Keycloak hostname together, so that a renewal does not break sign-in for one organization while the others keep working.
Named owner for client and mapping
Assign one person or team to own the Keycloak client registration, the redirect URIs, the client secret and the attribute mapping from Keycloak claims to Decidim user fields. Without a named owner, changes to claims or realms tend to break sign-in silently. Ask who approves changes, who rotates the secret and who checks the registration event after each change.
How a participant's login travels between Decidim and Keycloak
The flow starts when a participant chooses Keycloak on the Decidim sign-in page. Decidim redirects the browser to Keycloak's authorization endpoint, and the browser returns an authorization code to the OmniAuth callback. Decidim then exchanges that code at the token endpoint, reads user attributes from the user info endpoint, and matches or creates the local account. The registration event runs inside the Decidim host before the session is granted. Check that the redirect URIs match the provider configuration for each organization, and confirm that the attributes you map are the ones your verification policy relies on.
Login hand-offs between the participant, Decidim and the Keycloak realm.
Configuration sequence from Keycloak realm to live login
The sequence takes a Keycloak realm from planning to a verified test login in one Decidim organization, with each step closed by a check that confirms the previous one worked. Keep the test organization isolated until the final step passes.
Choose the realm and confidential clients
The Keycloak administrator creates or selects a realm for the participation platform and creates one confidential client per Decidim organization that will use SSO. Each client gets a client ID and a client secret, and the secret is stored in your secrets manager rather than in a shared document. Confirm that each client is set to confidential with the standard authorization code flow enabled, and that no client shares a secret with another organization. This keeps revocation and auditing per organization.
Set redirect URIs and token scopes
For each client, register the callback URL that Decidim will use for the OmniAuth provider, including the exact organization host and path. Add the scopes that return the attributes Decidim needs, such as email, name and any identifier you plan to map, and confirm which claims appear in the ID token or userinfo response. Test by comparing the registered redirect URI character by character with the value Decidim sends, since a trailing slash or a different hostname will fail the exchange. Record the mapping in a configuration document for review.
Add the custom OmniAuth provider to Decidim
The Decidim developer adds Keycloak as a custom OmniAuth strategy in the application, using the provider class and gem that match your Decidim version. Configuration keys, including the client ID, secret, site URL and realm path, must be taken from the Decidim social providers documentation for that release, not from examples in older posts. Keep the secret in environment variables or your secrets store. Confirm the application boots without errors and the provider appears in the sign-in options for the test organization only.
Map Keycloak attributes to Decidim user fields
Define how claims from Keycloak map to Decidim fields such as email, name and nickname, and decide how a returning user is matched to an existing account. Decide what happens when a claim is missing or the email is unverified, because a wrong match can link one person to another account. Verify the mapping with a test user whose attributes are known. The check is that the Decidim user record shows the expected values after login and that no duplicate account was created.
Enable the provider for one test organization
In the Decidim admin settings for a single test organization, enable the Keycloak provider and leave other organizations on their current sign-in methods. Confirm that the provider settings are scoped to that organization and that a second organization does not show the button. This isolates any misconfiguration to the test instance and gives the team a controlled environment to observe.
Run a login with a test account
Sign in with a dedicated Keycloak test account and follow the redirect to Keycloak, the consent step if one applies, and the return to Decidim. Confirm that the token exchange succeeds and that the returned claims are logged as expected, using the logging level your environment permits. Check the Decidim session, the user record and the Keycloak event log together. Then repeat the test with a failed case, such as a wrong password, to confirm that Decidim rejects the attempt cleanly.
Confirm the sequence before wider rollout
Review each check result with the security and identity owners before enabling SSO for further organizations or forcing it as the only registration path. Document the realm settings, client identifiers, redirect URIs and mapping decisions in a change record so the configuration can be reproduced. Only after this review should you move to the registration mode decisions covered elsewhere in this topic.
Mapping Keycloak claims to Decidim user attributes
This table lists each Keycloak claim, the Decidim field it fills, and how the value is handled at registration. Read it as a checklist for the mapping you configure and test. The main takeaway is that the returning-user key must come from the subject claim, and every mapping must be checked against the auth hash of the Decidim version you run.
| Decidim attribute | Keycloak source | Required at registration | Missing claim handling | Owner in Keycloak |
|---|---|---|---|---|
| Stable unique identifier | Subject (sub) from the ID token, unique per realm user | Yes | Reject sign-in and log the event; never create an account without it | Keycloak platform team, set by the realm and not editable by users |
| Verified email address | email claim, with email_verified checked | Yes | Stop registration and ask the participant to verify the address in Keycloak | Keycloak realm admins, through the email verification flow |
| Display name | name, or given_name and family_name combined | Yes | Fall back to the username or ask the participant to complete their profile | Keycloak user profile, editable by the user if policy allows |
| Nickname or username | preferred_username | No | Generate a nickname from the email local part, then let the participant change it | Keycloak realm admins |
| Locale | locale claim, mapped to a Decidim locale code | No | Use the organization default locale and let the participant choose later | Keycloak realm admins, set through the user locale attribute |
| Group or role for admin decisions | Custom groups or roles claim, configured as a mapper | No | Treat as no privilege; never grant admin rights from a missing claim | Keycloak realm admins, with a named owner for each group |
| Verification decision | Custom attribute or group that marks a verified citizen or member | No | Leave the user unverified so Decidim's authorization steps still apply | Agreed with the organization's identity or census owner |
Using the registration event to verify participants
A successful Keycloak login proves that the person authenticated against your identity provider. It does not, by itself, prove that the person is who your participation rules require. Before you let an SSO login count as verification in Decidim, decide which trust signal Keycloak will supply: the realm's assurance level for the authentication, a verified email address, or membership in a group that only your administrators can grant. Each one answers a different question. An assurance level says how strongly the user authenticated. A verified email says the user controls an inbox. A group says your organization vouched for the person. Many organizations need the group signal for voting or signing, because it reflects an enrollment decision made outside the self-service flow. Write the chosen signal down, and confirm with your own Keycloak administrators how each claim is populated in your realm before mapping it to any Decidim field.
The main risk is trusting self-registration. If Keycloak allows open sign-up, anyone can create an account, and a login from that account will look identical to a login from an enrolled citizen unless the token carries a signal that separates them. Treat self-registered accounts as unverified by default. Confirm whether your realm requires email verification before first login, whether registration is restricted to specific domains or invitations, and whether the claims Decidim receives can be changed by the user. Decidim's identity verification and authorization systems are the place where a verified participant status is recorded and checked, so the gate should rely on that record rather than on a raw claim that anyone could influence. Confirm in the Decidim documentation for your version how authorization handlers are configured before you wire them to voting or signing.
Before enabling any verification-gated action, test the full path with accounts you control. Create one account that is enrolled, one self-registered account that is not, and one account whose verified signal is removed after it was granted. Check that each account reaches the expected result for voting and signing, that a revoked signal takes effect at the next login or at the next authorization check, and that the attempt is recorded in your audit logs. Test the registration mode you chose, including the case where a participant tries to sign up through a path that bypasses Keycloak. Document the results and repeat the tests after every Keycloak or Decidim upgrade, since the claims and the authorization flow are both areas where a change can silently widen access.
Security settings that protect the Keycloak to Decidim login
A Keycloak login that Decidim trusts is only as safe as the client registration, token settings and admin paths behind it. The cards below cover the settings to agree with your security team before go-live, and the patch and reporting timelines that shape how the whole stack gets upgraded over time.
Confidential client secret handling
Register the Decidim client in Keycloak as a confidential client, so the client secret stays on the server side of the OmniAuth flow. Keep the secret in a secrets manager or the container platform's secret store, never in the Decidim repository or in a committed environment file. Check that rotation is possible without a full redeploy, and that logs and error pages never print the secret.
Keycloak admin docsExact redirect URIs only
Set the valid redirect URI for each Decidim organization to its exact callback address, including scheme, host and path. Avoid wildcards and broad patterns, since a loose redirect rule lets an attacker send a victim's authorization code to a host they control. Review the list each time a new organization or hostname is added to a multi-tenant Decidim instance.
TLS on every hop
Serve Decidim, Keycloak and the identity traffic between them over HTTPS, and confirm that the issuer URL in the provider configuration matches the certificate name exactly. Mixed HTTP and HTTPS paths let tokens and session cookies leak. Ask your team to confirm how certificates are issued, renewed and monitored in the environment where both services run.
Token lifetimes and session limits
Set access token, refresh token and SSO session lifetimes in the Keycloak realm with the security team, rather than accepting defaults by habit. Shorter lifetimes limit the exposure of stolen tokens, while very short sessions frustrate participants on long proposal drafts. Document the chosen values and the idle and maximum session times so they can be reviewed at each audit.
MFA enforced in the realm
Require multi-factor authentication in the Keycloak realm through its authentication flows, so the second factor applies to every login that reaches Decidim, not only to some clients. Decide with your team which roles, such as organization administrators, must always use MFA. Confirm how enrolment, recovery and lost-device cases are handled before participants are sent to the SSO login.
Restricted admin access and supported releases
Limit who can change the Decidim OmniAuth provider settings and the Keycloak client definition, and log every change. Keep Keycloak on a release line that still receives security fixes, and where the Keycloak Operator is used, set its update approval mode to manual so upgrades are reviewed before they run. Tie these changes to the Decidim patch window: Decidim supports only its last two minor versions with security updates before 1.0, and gives implementers 2 months for standard vulnerabilities and 4 months for critical ones. Report suspected Decidim flaws to security@decidim.org or through GitHub Security Advisories, and plan Decidim and Keycloak upgrades inside those windows.
- Patch grace periods
- 2 and 4 months
Choosing registration modes, including SSO-only access
Open registration suits a public participation platform where Keycloak is one sign-in option alongside the local Decidim account and other configured providers. Participants choose the method they already use, and anyone with a local account keeps access if Keycloak has an outage. This mode fits organizations that want to widen participation first and tighten identity later.
- Existing accounts: Participants keep their local Decidim accounts. Test how a Keycloak sign-in links to an existing account that uses the same email address before launch, including what happens when the emails differ.
- Administrators: Administrators keep their current roles. Confirm that users who arrive through Keycloak receive the same default roles and permissions as local users.
- Lockout risk: Low, because local login remains available if Keycloak is unavailable.
- Verification gaps: A Keycloak sign-in does not prove that a person is a verified participant. Pair it with Decidim's authorization workflows wherever voting or signing requires verification.
- Break-glass account: Keep a local Decidim administrator with a stored password and a second factor, and test that login before go-live.
Before choosing this mode, confirm how the target version handles account linking and whether the Keycloak option appears on the sign-in page for each organization.
A migration period suits organizations moving an existing participant base from local Decidim accounts to central identity. Both paths work during the overlap, which lets participants move at their own pace. The main risks are duplicate accounts with the same email address, password resets that diverge between the two systems, and an unclear date for retiring local login.
- Who it suits: Organizations with a large existing user base and a decision on when local passwords will stop being accepted.
- Existing accounts: Decide how a participant who signs in through Keycloak matches an existing Decidim account. Test matching by email, and define the process for accounts whose emails do not match.
- Administrators: Staff who manage accounts need a runbook for duplicate accounts, locked accounts and password reset requests during the overlap.
- Lockout risk: Moderate. Two sign-in paths make failures easier to isolate, but participants may be unsure which login to use. A Keycloak outage still leaves local login available.
- Break-glass account: Keep a local administrator in place for the whole overlap and until the final cutover is complete.
Before setting a cutover date, confirm the target version's settings for showing both login options and the exact steps for retiring local login.
SSO-only access suits organizations whose policy requires every account to authenticate through a central identity provider. In this mode, local registration and password login are disabled for that organization. It carries the highest lockout risk of the three modes, so it should only follow a tested Keycloak deployment.
- Who it suits: Organizations with a written policy for central identity and a Keycloak deployment that has been tested for availability. The Keycloak high availability overview describes the database replication that supported designs require.
- Existing accounts: Local accounts stop working in this mode. Map each one to a Keycloak user before cutover, and tell participants how to recover access through the identity provider.
- Administrators: Move administrator accounts to Keycloak as well, but keep the break-glass account outside the forced path.
- Lockout risk: High. If Keycloak or its database fails, normal sign-in stops for everyone. Plan monitoring, a documented recovery procedure and an agreed response owner.
- Break-glass account: Store its credentials offline, limit its use to incidents, log every use and test the recovery path in a non-production environment. Confirm whether the target version still allows a local administrator to sign in when forced SSO is enabled.
Before enabling this mode in production, confirm the forced SSO setting in the target version and verify the break-glass login end to end.
Common failures in Keycloak SSO for Decidim and how to fix them
This table lists the failures teams most often hit when wiring Keycloak into Decidim through OmniAuth, with the likely cause, how to confirm it in logs or Keycloak events, and the fix. Work down the rows in order of how early each failure appears, starting with redirect and client settings, then identity mapping, then access policy and upgrades.
| Failure | Likely cause and how to confirm it | Fix |
|---|---|---|
| Redirect URI mismatch | The callback URL registered in the Keycloak client does not match the Decidim host and path for that organization. Keycloak shows an invalid redirect URI error on the login screen, and the Keycloak event log records a LOGIN_ERROR for the client. | Register the exact callback URL for each organization host, including scheme and port, in the client's valid redirect URIs. Test each organization separately. |
| Client secret mismatch | The secret stored in Decidim's provider settings differs from the secret in the Keycloak client's credentials tab, often after rotation. Keycloak logs a failed client authentication at the token step. | Rotate or copy the secret into Decidim's secrets store for that organization, then restart the application so the new value loads. Confirm with a fresh login attempt. |
| Missing email or subject claim | The client scopes do not include the email claim or the subject identifier is not sent as expected. Decidim rejects the sign-in or creates a user without an email address, which the application log shows as a failed or incomplete authentication. | Add the email and profile mappers to the client scope, confirm them in the token preview of the Keycloak client, and map the claims to the fields Decidim reads in the provider configuration. |
| Duplicate accounts after identifier change | The field Decidim uses to match an existing user changed, for example from email to a username or from one realm to another. Participants appear to sign in as new users and their proposals appear under a second account. | Keep one stable identifier for matching, such as the Keycloak subject, and document the mapping before go-live. Merge or reconcile duplicates in Decidim's administration tools with a documented process. |
| Clock skew or expired tokens | The Decidim host and the Keycloak server disagree on time, so tokens appear expired or not yet valid. Errors refer to token timing in the application log, and the failure is intermittent across users. | Synchronize both servers with NTP, check time zones in both logs, and keep token lifetimes at the values agreed with your security team. |
| Wrong realm or host for the organization | A multi-organization Decidim instance points one organization at a Keycloak realm or issuer configured for another host, so users land on the wrong login or see another organization's branding. Check the issuer and realm in the provider settings against the organization's host. | Set provider configuration per organization and verify issuer, realm and host for each one. Test sign-in on every host before enabling SSO for it. |
| Users locked out when SSO is forced | Registration modes that force SSO remove the local password path before participants have a linked Keycloak account, or a user cannot complete the verification step. Support sees users who cannot reach the sign-in page or stall at the registration event. | Plan the cutover with a communication period, keep an administrator path for recovery, and test the verification steps for existing participants before forcing SSO. Confirm the exact behavior of the registration mode in your Decidim version. |
| Breakage after a minor-version upgrade | The provider configuration, custom code or secrets were not carried over when moving to a new Decidim minor version, so the OmniAuth provider fails to load. Confirm by reviewing the upgrade notes and the startup log after the change. | Upgrade one minor version at a time, back up the database first, and carry the provider configuration into the new release's settings. Retest SSO on a staging copy before the production upgrade. |
Questions teams ask before connecting Keycloak to Decidim
How much effort does a Keycloak login for Decidim take?
The effort depends on how many pieces you build and how many organizations sign in through Keycloak. The main work is configuring a custom OmniAuth provider per Decidim organization, mapping the claims Keycloak sends to the Decidim user fields you need, testing the login path end to end, and deciding how the registration flow behaves for new users. Effort rises when you have several Decidim organizations with different realms or clients, when attribute mapping needs custom logic, when you enforce SSO for every participant, or when the registration event must trigger verification steps. Ask any partner for a written breakdown of these items so you can compare scope rather than headline totals.
How long should we plan for before the first working login?
Plan the timeline around the dependencies, not around a fixed number. The first working login usually waits on the Keycloak client registration, the redirect URI and HTTPS setup for your Decidim host, and a test realm with sample users. Access approvals and change windows in your own organization often take longer than the code change itself. Ask the implementer to list each dependency with an owner and a date, and confirm the sequence in writing before work starts. Because the upgrade path for both Decidim and Keycloak matters, include a review of the versions you plan to run.
Can our internal team connect Keycloak to Decidim without an outside partner?
Yes, if your team has Ruby on Rails experience, can run Decidim from its manual or Docker installation, and can administer Keycloak clients and realms. Decidim's social providers documentation describes how custom OmniAuth strategies are added, so the work is within the reach of a capable engineering team. The risks are in the details: security settings for the client, handling of user identifiers and emails, and testing of the registration path. Many organizations bring in an outside team for the security review, the test plan and the knowledge transfer, while keeping day-to-day ownership in-house.
What does our organization need to provide before work starts?
Prepare the following before the implementation starts:
- Administrator access to the Keycloak server, with permission to create a realm, clients, and client scopes
- DNS records for the Decidim host names and for the Keycloak host
- TLS certificates issued for those hostnames, with the chain your browsers and Decidim servers trust
- A test realm with test users that mirror the attributes your production users carry
- Named approvers for the attribute mapping, the registration rules, and the go-live decision
Confirm these items in the written scope so that delays in any one of them are visible early.
What recurs after go-live for Decidim and Keycloak?
Several tasks recur after go-live. Decidim releases follow a minor-version path, and the update guide asks you to move one minor version at a time, back up the database first, and follow each release's upgrade instructions. Keycloak publishes minor releases several times a year, and its upgrading guide covers schema migration at startup. Certificates expire and need renewal. Each Decidim or Keycloak upgrade should trigger a repeat of the SSO login tests, including the registration event and the forced-SSO modes. Budget for these tasks as an ongoing operating cost, and ask any partner whether they offer a retainer for upgrades and testing.
How does a quote follow from the scope for this integration?
A quote follows from a written scope. The scope lists the Decidim organizations involved, the Keycloak realms and clients, the attributes to map, the registration and verification behavior, the registration modes that force SSO, the test cases, the documentation, and the handover. Each item is an effort driver. Ask the provider to state what is included, what is excluded, which tasks are one-time, and which tasks recur, such as upgrades and certificate renewal. Compare quotes against the same scope, because a lower total can simply mean fewer tests or no handover. DeployOpen does not publish a price list. Its engagements are fixed-scope, with scope, deliverables and timelines agreed in writing before work starts.
Which claims from Keycloak should we check before mapping user attributes?
Check the claims your Keycloak client actually sends, because the mapping depends on them. Confirm which identifier is stable across the life of an account, whether email is verified in Keycloak, and which name fields are populated for your users. Decide how Decidim should handle a missing or changed email address before any user logs in. Test each case with a few realistic sample accounts in the test realm. Keycloak's server administration guide describes how client scopes and mappers shape the tokens, so confirm your settings against that guide rather than assuming defaults.
How DeployOpen scopes and delivers Decidim SSO with Keycloak
DeployOpen plans and implements Decidim single sign-on with a Keycloak instance you control, wiring Keycloak in as a custom OmniAuth provider for each organization on the platform. The work is scoped in writing before build starts, then tested, documented and handed to your team to run.
How we scope
- Confirm which Decidim organizations on the platform will use Keycloak and which keep existing login methods.
- Agree the Keycloak realm, client settings, attribute mapping and verification rules in a written scope before work starts.
- Engagements are fixed-scope, and ongoing support, upgrades and continuous testing are available as retainers.
How we build
- Configure the Keycloak client and the Decidim OmniAuth provider per organization, with redirect URIs checked against each domain.
- Map Keycloak claims to Decidim user fields and test edge cases such as missing emails and changed usernames.
- Set up the registration event and registration modes that force SSO, then test sign-in, sign-out and account linking end to end.
How we hand over
- Deliver configuration as code or documented settings, with the Keycloak client definitions and Decidim provider settings recorded.
- Provide test results, a runbook for adding a new organization and notes on the Decidim version the work was validated against.
- Walk your identity and platform teams through the configuration so they can review it against their own security requirements.
How we support
- Plan Keycloak and Decidim upgrades as separate steps, with database backups taken before each Decidim minor version change.
- Retest SSO sign-in after each Keycloak or Decidim upgrade, since either can change behavior that the login flow depends on.
- Confirm with your team which Keycloak release line and support terms apply to your environment before the scope is signed.

