Skip to content
Display

Display

Star12.2k

Self-hosting

Set up Keycloak single sign-on (SSO)

  • Self-hosted only

At a glance

TimeAbout 30 min

LevelSome experience

You need

  • Leantime 3.13.2 or later (older versions don't send PKCE; leave Require PKCE off on those)
  • A Keycloak server, with an administrator account

Where you'll work

  1. The Keycloak admin console
  2. Leantime's .env file, or the Leantime container's environment
  3. A terminal on the Leantime server, to apply the settings
  4. Leantime's login page, in a private browser window

At the end

An OIDC Login button on Leantime's login page that signs people in with Keycloak. People who sign in for the first time get a Leantime account automatically, if you allow it.

Markdown

Your team can sign in to Leantime with their Keycloak accounts, using the OpenID Connect (OIDC) support built into Leantime. No plugin is needed for the web app. This guide gives every step for doing it by hand, and the prompts to use if an AI assistant is helping you.

Three addresses matter. Write yours down before you start:

What Example Where you’ll use it
Leantime’s address https://projects.example.com LEAN_APP_URL in Leantime
Your Keycloak realm’s address (the issuer) https://auth.example.com/realms/leantime LEAN_OIDC_PROVIDER_URL in Leantime
Leantime’s callback address https://projects.example.com/oidc/callback Valid redirect URIs in Keycloak

When someone clicks the login button, Leantime sends them to Keycloak. They sign in there, and Keycloak sends them back to the callback address with a one-time code. Leantime swaps the code for a signed token that says who they are, and logs them in by their email address.

A realm is a separate set of users and apps. You can use an existing one; skip to step 2.

  1. Open the Keycloak admin console (https://auth.example.com/admin/) and sign in.
  2. Click Manage realms, then Create realm.
  3. Enter a Realm name, for example leantime, and click Create.

Your issuer is now https://auth.example.com/realms/leantime.

  1. In your realm, open Clients and click Create client.
  2. General settings: leave Client type as OpenID Connect. Enter leantime as Client ID and Leantime as Name. Click Next.
  3. Capability config:
    • Turn Client authentication on. Leantime keeps a client secret, so it’s a confidential client.
    • Keep Standard flow checked. You don’t need the other flows.
    • Turn Require PKCE on. Leantime 3.13.2 and later send PKCE, which protects the login code.
    • Click Next.
  4. Login settings:
    • Root URL: https://projects.example.com
    • Valid redirect URIs: https://projects.example.com/oidc/callback
    • Web origins: https://projects.example.com
    • Click Save.
  5. Open the Credentials tab and copy the Client Secret. Treat it like a password.

Step 3: Make sure users have a verified email

Section titled “Step 3: Make sure users have a verified email”

Leantime finds the account by email address, so every user needs one. Because of that, Leantime also refuses addresses that Keycloak marks as unverified.

  • For a user you create by hand: in Users, open the user and turn Email verified on.
  • For self-registration: let Keycloak verify addresses by email (Realm settings → Login → Verify email).

Add these to Leantime’s .env file, or to the environment of the Leantime container:

LEAN_APP_URL = 'https://projects.example.com'
LEAN_OIDC_ENABLE = true
LEAN_OIDC_PROVIDER_URL = 'https://auth.example.com/realms/leantime'
LEAN_OIDC_CLIENT_ID = 'leantime'
LEAN_OIDC_CLIENT_SECRET = '<client secret from step 2>'
LEAN_OIDC_CREATE_USER = true
LEAN_OIDC_DEFAULT_ROLE = 20
  • LEAN_OIDC_PROVIDER_URL must be exactly the issuer: the realm address, with no /.well-known/... on the end. A trailing slash doesn’t matter: Leantime removes it before comparing.
  • LEAN_OIDC_CREATE_USER = true creates a Leantime account the first time someone signs in. With false, only people who already have a Leantime account with the same email can sign in.
  • LEAN_OIDC_DEFAULT_ROLE is the role for new accounts: 5 Read Only, 10 Commenter, 20 Editor, 30 Company Manager, 40 Administrator.
  • Leantime reads the email, first name and last name from Keycloak’s standard email, given_name and family_name claims, so no mapping is needed.

Then apply the settings. In Docker, run docker compose up -d; a restart alone keeps the old settings. On a server, reload PHP-FPM or your web server.

  1. Open Leantime’s login page in a private browser window. Below the login form you’ll see OIDC Login.
  2. Click it, sign in with a Keycloak user, and you land on the Leantime dashboard.
  3. As an administrator, open Company → User Management in Leantime: the new person is there with the default role. Change their role or add them to projects as usual.

“The received provider … does not match the local setting …”

Section titled ““The received provider … does not match the local setting …””

LEAN_OIDC_PROVIDER_URL isn’t exactly the issuer in Keycloak’s token. Copy the issuer value from https://auth.example.com/realms/leantime/.well-known/openid-configuration and paste it as the setting.

This also happens when Leantime and Keycloak run on the same computer. See Testing on one machine.

“Your identity provider reports that the email address of your account is not verified.”

Section titled ““Your identity provider reports that the email address of your account is not verified.””

The Keycloak user’s Email verified is off. Turn it on (step 3), then sign in again. Only if you fully trust every address in your Keycloak can you skip the check with LEAN_OIDC_REQUIRE_VERIFIED_EMAIL = false.

Keycloak says “Invalid parameter: redirect_uri”

Section titled “Keycloak says “Invalid parameter: redirect_uri””

The callback address in Keycloak’s Valid redirect URIs doesn’t match Leantime’s. Check LEAN_APP_URL: Leantime builds the callback from it, so http:// versus https:// or a missing port makes them differ.

LEAN_OIDC_ENABLE isn’t true, or the container wasn’t recreated after you changed .env.

When Leantime runs in Docker and Keycloak runs on the same computer, the browser reaches Keycloak at http://localhost:8180, but the Leantime container can’t: inside the container, localhost is the container itself. In production, with public addresses, this doesn’t happen. For a local test:

  • Start Keycloak with KC_HOSTNAME=http://localhost:8180 and KC_HOSTNAME_BACKCHANNEL_DYNAMIC=true.

  • Put both containers on one Docker network.

  • In Leantime, set the issuer as the provider, and tell Leantime where to fetch Keycloak’s settings from inside Docker:

    LEAN_OIDC_PROVIDER_URL = 'http://localhost:8180/realms/leantime'
    LEAN_OIDC_AUTO_DISCOVER = 'http://keycloak:8080/realms/leantime'

Does this work with the Leantime mobile app?

Section titled “Does this work with the Leantime mobile app?”

Yes, with the same Keycloak client; there’s nothing extra to set up in Keycloak. Signing in to the mobile app through single sign-on also needs the Advanced Authentication plugin enabled on your Leantime server.

An AI assistant that can run commands (Claude Code, Cursor, Codex or similar) can do most of this setup. A chat assistant (Claude, ChatGPT) can guide you step by step. Either way, give it the facts first, so it doesn’t guess setting names.

1. Give it this guide. Give it the Markdown address https://docs.leantime.io/installation/keycloak-sso.md, or open that address and paste the text into the chat.

2. Tell it your setup. For example:

I want my team to sign in to our self-hosted Leantime with Keycloak, using
Leantime's built-in OIDC support. Follow the guide I pasted.
- Leantime 3.14 runs in Docker Compose at https://projects.example.com
- Keycloak 26 runs at https://auth.example.com, realm "leantime"
- New users should get a Leantime account as Editor.
Walk me through it one step at a time and wait for me to confirm each step.
Use only setting names from the guide. Don't ask me for the client secret;
I'll put it into .env myself.

3. When something fails, give it the exact error. Copy the message from Leantime’s login page or the last lines of docker compose logs leantime, and ask what it means according to the guide.

What not to paste into an AI chat: the client secret, your .env file with passwords, admin passwords, or tokens. Replace them with <client secret> and so on; the assistant doesn’t need them to help.

Was this page helpful?