Self-hosting
Authentication: OIDC, LDAP and single sign-on
- Self-hosted only
At a glance
You need
- An identity provider that supports OpenID Connect (such as Keycloak, Authentik, Google or Microsoft Entra ID), or an LDAP or Active Directory server
- For LDAP: the PHP
ldapextension on the Leantime server
Where you'll work
- Your identity provider's admin console, to register Leantime (OIDC)
- Leantime's
.envfile, or the container's environment
At the end
People sign in to Leantime with their company accounts, through OIDC single sign-on or LDAP.
Leantime supports multiple authentication methods to integrate with your organization’s identity infrastructure. This guide covers OpenID Connect (OIDC) and LDAP configuration.
Authentication Methods Overview
Section titled “Authentication Methods Overview”| Method | Best For | Requirements |
|---|---|---|
| Built-in | Small teams, simple setup | None (default) |
| OIDC | SSO with modern identity providers | OIDC-compliant provider |
| LDAP | Enterprise Active Directory / OpenLDAP | LDAP server access |
| AdvancedAuth plugin | Sign-in buttons for Google, Microsoft, GitHub and other providers, or SAML 2.0 | AdvancedAuth plugin |
OpenID Connect (OIDC)
Section titled “OpenID Connect (OIDC)”OIDC enables single sign-on (SSO) with identity providers like Keycloak, Authentik, Google Workspace, Azure AD, and others.
Quick Start
Section titled “Quick Start”Add these to your .env file or environment variables:
LEAN_OIDC_ENABLE=trueLEAN_OIDC_PROVIDER_URL=https://your-provider.com/LEAN_OIDC_CLIENT_ID=your-client-idLEAN_OIDC_CLIENT_SECRET=your-client-secret
# Create a Leantime account on a user's first OIDC login (default: false)LEAN_OIDC_CREATE_USER=true# Role for those accounts (default: 20, editor)LEAN_OIDC_DEFAULT_ROLE=20Without LEAN_OIDC_CREATE_USER=true, only people who already have a Leantime account (with the same email) can sign in. Everyone else gets a “user not found” error.
Callback URL: Configure your identity provider to allow:
https://your-leantime-domain.com/oidc/callbackKey algorithms: Configure your identity provider to sign tokens with RS256 (RSA with SHA-256). Other algorithms, including elliptic-curve keys (ES256) and RS384/RS512, are rejected.
PKCE: Leantime sends PKCE (S256) since v3.13.2, so providers that require it work. On older versions, disable PKCE for the Leantime client in your identity provider.
How users are matched: Leantime matches the email address from the provider to the Leantime user’s email. If a user’s email changes at the provider, Leantime treats them as a new person. Change their email in Leantime to match before they next sign in.
Verified emails: If the provider reports email_verified: false, the login is refused. Set LEAN_OIDC_REQUIRE_VERIFIED_EMAIL=false only if your provider marks real users as unverified.
Provider-Specific Configuration
Section titled “Provider-Specific Configuration”Keycloak
Section titled “Keycloak”LEAN_OIDC_ENABLE=trueLEAN_OIDC_PROVIDER_URL=https://keycloak.example.com/realms/your-realm/LEAN_OIDC_CLIENT_ID=leantimeLEAN_OIDC_CLIENT_SECRET=your-client-secretKeycloak setup:
- Create a new OpenID Connect client in your realm
- Turn on Client authentication (called Access Type “confidential” in Keycloak 18 and earlier)
- Add the callback URL to Valid Redirect URIs
- Copy the client secret from the Credentials tab
Keycloak users whose email isn’t marked as verified are refused (see Verified emails above).
For every step, and the errors you might hit, see Set up Keycloak single sign-on.
Authentik
Section titled “Authentik”LEAN_OIDC_ENABLE=trueLEAN_OIDC_PROVIDER_URL=https://auth.example.com/application/o/leantime/LEAN_OIDC_CLIENT_ID=your-client-idLEAN_OIDC_CLIENT_SECRET=your-client-secretAuthentik setup: In the OAuth2/OpenID provider, select an RSA certificate as the Signing Key and leave the Encryption Key empty. Without a signing key, Authentik signs with HS256, which Leantime rejects. With an encryption key, tokens are encrypted, and login fails with errors like “Undefined array key kid” or “JWT could not be decoded”.
Authentik 2025.10 and later: The default email scope mapping reports every email as unverified (email_verified: false), so Leantime refuses the login. Replace it on the provider with a custom mapping that returns email_verified (see Authentik’s verify email address guide), or set LEAN_OIDC_REQUIRE_VERIFIED_EMAIL=false if every Authentik address is trusted.
Google / Google Workspace
Section titled “Google / Google Workspace”LEAN_OIDC_ENABLE=trueLEAN_OIDC_PROVIDER_URL=https://accounts.google.com/LEAN_OIDC_CLIENT_ID=your-client-id.apps.googleusercontent.comLEAN_OIDC_CLIENT_SECRET=your-client-secretLEAN_OIDC_JWKS_URL_OVERRIDE=https://www.googleapis.com/oauth2/v1/certsGoogle Cloud Console setup:
- Go to APIs & Services → Credentials
- Create OAuth 2.0 Client ID
- Set application type to “Web application”
- Add the callback URL to Authorized redirect URIs
GitHub
Section titled “GitHub”GitHub sign-in is plain OAuth 2.0, not OpenID Connect, so it needs the URL overrides below. Leantime never contacts LEAN_OIDC_PROVIDER_URL for GitHub, but it has to be set.
LEAN_OIDC_ENABLE=trueLEAN_OIDC_PROVIDER_URL=https://github.com/LEAN_OIDC_AUTH_URL_OVERRIDE=https://github.com/login/oauth/authorizeLEAN_OIDC_TOKEN_URL_OVERRIDE=https://github.com/login/oauth/access_tokenLEAN_OIDC_USERINFO_URL_OVERRIDE=https://api.github.com/user,https://api.github.com/user/emailsLEAN_OIDC_SCOPES=user:emailLEAN_OIDC_FIELD_EMAIL=0.emailLEAN_OIDC_FIELD_FIRSTNAME=nameLEAN_OIDC_CLIENT_ID=your-github-client-idLEAN_OIDC_CLIENT_SECRET=your-github-client-secretWarning: don’t use this for sign-in in production.
0.emailis simply the first address GitHub lists for the user. It can be an address they added but never verified, and core OIDC only checks a top-levelemail_verifiedclaim, which GitHub doesn’t send. Because users are matched by email, someone could add an existing colleague’s address to their GitHub account and sign in as that colleague. Use the AdvancedAuth plugin’s GitHub provider instead: it only uses the primary, verified address.
Azure AD / Entra ID
Section titled “Azure AD / Entra ID”LEAN_OIDC_ENABLE=trueLEAN_OIDC_PROVIDER_URL=https://login.microsoftonline.com/your-tenant-id/v2.0/LEAN_OIDC_CLIENT_ID=your-application-idLEAN_OIDC_CLIENT_SECRET=your-client-secretIf sign-in fails because no email is available, your tenant isn’t sending the optional email claim. Add email as an optional ID token claim in the app registration (Token configuration → Add optional claim), or set LEAN_OIDC_FIELD_EMAIL=preferred_username if users’ sign-in names are their email addresses.
All OIDC Environment Variables
Section titled “All OIDC Environment Variables”## RequiredLEAN_OIDC_ENABLE=true # Enable OIDC authenticationLEAN_OIDC_PROVIDER_URL= # Provider's issuer / base URL (a trailing slash is optional)LEAN_OIDC_CLIENT_ID= # Client ID from your providerLEAN_OIDC_CLIENT_SECRET= # Client secret from your provider
## AccountsLEAN_OIDC_CREATE_USER=false # Create accounts on first loginLEAN_OIDC_DEFAULT_ROLE=20 # Role for created accounts (5 readonly ... 50 owner)LEAN_OIDC_REQUIRE_VERIFIED_EMAIL=true # Refuse logins whose email_verified claim is false
## URL Overrides (optional - auto-discovered from .well-known if not set)LEAN_OIDC_AUTH_URL_OVERRIDE= # Authorization endpointLEAN_OIDC_TOKEN_URL_OVERRIDE= # Token endpointLEAN_OIDC_USERINFO_URL_OVERRIDE= # Userinfo endpoint (comma-separated for multiple)LEAN_OIDC_JWKS_URL_OVERRIDE= # JWKS endpoint for key validation
## Certificate Overrides (optional - for custom RSA validation)LEAN_OIDC_CERTIFICATE_STRING= # Public key as stringLEAN_OIDC_CERTIFICATE_FILE= # Path to public key file
## Scope and Field Mapping (optional)LEAN_OIDC_SCOPES= # Custom scopes (default: openid profile email)LEAN_OIDC_FIELD_EMAIL= # Path to the email field (default: email)LEAN_OIDC_FIELD_FIRSTNAME= # Path to the first name field (default: given_name)LEAN_OIDC_FIELD_LASTNAME= # Path to the last name field (default: family_name)LEAN_OIDC_FIELD_PHONE= # Path to the phone fieldLEAN_OIDC_FIELD_JOBTITLE= # Path to the job title fieldLEAN_OIDC_FIELD_JOBLEVEL= # Path to the job level fieldLEAN_OIDC_FIELD_DEPARTMENT= # Path to the department field
## Network (troubleshooting only)LEAN_OIDC_SKIP_TLS_VERIFY=false # Never enable in productionField mapping note: Use dot notation for nested fields, e.g., user.profile.email. When the provider returns an ID token, fields are read from its claims and the userinfo URL isn’t called.
OIDC Troubleshooting
Section titled “OIDC Troubleshooting”Redirect Loop or “Too Many Redirects”
Section titled “Redirect Loop or “Too Many Redirects””Symptoms: The browser keeps bouncing between Leantime and the provider, or shows ERR_TOO_MANY_REDIRECTS.
Solutions:
- Check that the Leantime server (not just your browser) can reach the provider’s discovery document. In Docker, run this inside the Leantime container:
If the provider is only reachable by an internal hostname, fix the container’s networking or set the
Terminal window curl https://your-provider.com/.well-known/openid-configuration*_URL_OVERRIDEvariables. - Check that
LEAN_APP_URLmatches your actual domain (including https). - If
LEAN_SESSION_SECURE=trueis set but users reach Leantime over plain HTTP, the browser never sends the session cookie back and every request starts a new login. Serve Leantime over HTTPS (and keepLEAN_SESSION_SECURE=true), or set it tofalseonly if you really run plain HTTP. It is not detected automatically: when unset, cookies are sent without the Secure flag.
“User not found”
Section titled ““User not found””The person has no Leantime account with that email and LEAN_OIDC_CREATE_USER isn’t true. Create the user with the same email, or turn on account creation.
New Users Can’t See Any Projects
Section titled “New Users Can’t See Any Projects”Accounts created on first login aren’t added to any projects or client. Add them to projects, or assign a client, in user management.
Logging Out of Leantime Doesn’t Log Out of the Provider
Section titled “Logging Out of Leantime Doesn’t Log Out of the Provider”Leantime ends only its own session. The next OIDC login signs the user straight back in while their provider session is active. To switch users, sign out at the provider too.
Owner Role Was Reset After Enabling OIDC
Section titled “Owner Role Was Reset After Enabling OIDC”Older Leantime versions could reset an existing user’s role on OIDC login. Current versions keep the existing role. To restore an owner, run this with the account’s email (roles are stored as numbers: 50 is owner):
UPDATE zp_user SET role = '50' WHERE username = 'owner@example.com';LDAP Configuration
Section titled “LDAP Configuration”Since: v2.1.9
Leantime supports LDAP integration with OpenLDAP and Active Directory for centralized user authentication. The PHP ldap extension must be installed.
Quick Start
Section titled “Quick Start”LEAN_LDAP_USE_LDAP=trueLEAN_LDAP_LDAP_TYPE=OLLEAN_LDAP_HOST=ldap.example.comLEAN_LDAP_PORT=389LEAN_LDAP_DN=CN=users,DC=example,DC=comBasic Configuration
Section titled “Basic Configuration”## Enable LDAPLEAN_LDAP_USE_LDAP=true
## Directory TypeLEAN_LDAP_LDAP_TYPE='OL' # OL = OpenLDAP, AD = Active Directory
## Connection Settings (plain LDAP, port 389)LEAN_LDAP_HOST='ldap.example.com' # LDAP server hostname (FQDN)LEAN_LDAP_PORT=389
## Alternative: Use a URI instead of host/port. Required for LDAPS (TLS):LEAN_LDAP_URI='ldaps://ldap.example.com:636'
## User LocationLEAN_LDAP_DN='CN=users,DC=example,DC=com'
## Domain (Active Directory only - appended to usernames typed without @domain)LEAN_LDAP_LDAP_DOMAIN='example.com'LDAPS: Setting LEAN_LDAP_PORT=636 with LEAN_LDAP_HOST does not turn on TLS. Use LEAN_LDAP_URI='ldaps://host:636'. The Leantime server must also trust the directory’s certificate (its CA must be in the system trust store, or set TLS_CACERT in ldap.conf).
How users sign in: With AD, users can type username or username@domain. With OL, Leantime binds as {username attribute}={what they typed},{LEAN_LDAP_DN}, and LEAN_LDAP_LDAP_DOMAIN is not used.
Field Mapping
Section titled “Field Mapping”Configure how Leantime maps LDAP attributes to user fields. Write the JSON on one line, in single quotes. Multi-line or escaped JSON is a common reason for the “Ldap Keys failed to parse” error, and Leantime then silently uses the defaults.
LEAN_LDAP_KEYS='{"username":"uid","groups":"memberof","email":"mail","firstname":"givenname","lastname":"sn","phone":"telephonenumber","jobTitle":"title","jobLevel":"level","department":"department"}'- Capitals don’t matter in attribute names.
memberOfandmemberofboth work; Leantime compares them in lowercase. - Keys you leave out use the defaults:
uidfor username,memberoffor groups,mailfor email,displaynamefor first name, no last name,telephonenumberfor phone,title,levelanddepartment. List every key your directory names differently. - The Leantime setting wins. If the
companysettings.ldap.ldapKeyssetting exists in the database, it is used instead ofLEAN_LDAP_KEYS.
Common attribute mappings:
| Leantime Field | OpenLDAP | Active Directory |
|---|---|---|
| username | uid or cn |
samaccountname |
mail |
mail or userprincipalname |
|
| firstname | givenname |
givenname |
| lastname | sn |
sn |
| groups | memberof |
memberof |
| phone | telephonenumber |
telephonenumber |
Group Role Assignment
Section titled “Group Role Assignment”Map LDAP groups to Leantime roles. Each ldapRole is matched as text inside the user’s group DNs (memberof values), so use a distinctive part of the DN, for example CN=Leantime-Admins. Capitals don’t matter.
LEAN_LDAP_GROUP_ASSIGNMENT='{"30":{"ltRole":"manager","ldapRole":"CN=Leantime-Managers"},"40":{"ltRole":"admin","ldapRole":"CN=Leantime-Admins"},"50":{"ltRole":"owner","ldapRole":"CN=Leantime-Owners"}}'Role keys: 5 (readonly), 10 (commenter), 20 (editor), 30 (manager), 40 (admin), 50 (owner)
Rules:
- A user gets the highest role whose group matches.
- Only roles above
LEAN_LDAP_DEFAULT_ROLE_KEYcan be assigned. With the default of 20, mappings for 5 and 10 never apply. - Group roles are applied only when the account is created on the user’s first login. Later group changes don’t update the role. Change it in user management.
- Give every role its own group. If two roles use the same
ldapRole, the higher one always wins.
Default Role
Section titled “Default Role”The role new users get when none of their groups matches. It is also the minimum: group mappings can only raise it.
LEAN_LDAP_DEFAULT_ROLE_KEY=20 # Editor roleActive Directory Example
Section titled “Active Directory Example”LEAN_LDAP_USE_LDAP=trueLEAN_LDAP_LDAP_TYPE='AD'LEAN_LDAP_URI='ldaps://dc01.corp.example.com:636'LEAN_LDAP_DN='OU=Users,DC=corp,DC=example,DC=com'LEAN_LDAP_LDAP_DOMAIN='corp.example.com'
LEAN_LDAP_KEYS='{"username":"samaccountname","groups":"memberof","email":"userprincipalname","firstname":"givenname","lastname":"sn","phone":"telephonenumber","jobTitle":"title","jobLevel":"level","department":"department"}'
LEAN_LDAP_GROUP_ASSIGNMENT='{"30":{"ltRole":"manager","ldapRole":"CN=Leantime-Managers"},"40":{"ltRole":"admin","ldapRole":"CN=Leantime-Admins"}}'
LEAN_LDAP_DEFAULT_ROLE_KEY=20LDAP Troubleshooting
Section titled “LDAP Troubleshooting”Turn on LEAN_DEBUG=1 first: LDAP connection and bind errors are only written to the log in debug mode.
Users Get “Wrong Username or Password”
Section titled “Users Get “Wrong Username or Password””If the LDAP bind fails, Leantime quietly falls back to its own user database, so the user sees the normal login error. Check:
- The PHP
ldapextension is installed (the log says “Can’t use ldap. Extension not installed” if not). - The server is reachable from the Leantime server:
telnet ldap.example.com 389(or 636 for LDAPS). LEAN_LDAP_DNand theusernameattribute match what users type.- For LDAPS, the certificate is trusted (see LDAPS above).
“Could Not Retrieve User by Email”
Section titled ““Could Not Retrieve User by Email””The bind worked, but the email attribute was empty. Check that the email key names the right attribute (mail or userPrincipalName), and that users have that attribute set.
Everyone Gets the Default Role
Section titled “Everyone Gets the Default Role”- Check that
groupsnames the attribute that holds the user’s groups (usuallymemberOf). - Make each
ldapRolematch text in the group DN. Capitals don’t matter. - Roles are only assigned when the account is created. Existing users keep their role.
“Ldap Keys Failed to Parse” or “Group Assignment Array Failed to Parse” in the Log
Section titled ““Ldap Keys Failed to Parse” or “Group Assignment Array Failed to Parse” in the Log”The JSON isn’t valid, so Leantime uses its defaults. Write it on one line in single quotes, as in the examples above.
General Login Troubleshooting
Section titled “General Login Troubleshooting”Correct Password, but the Login Page Just Reloads
Section titled “Correct Password, but the Login Page Just Reloads”The session cookie isn’t being kept:
- If
LEAN_SESSION_SECURE=trueis set but you serve plain HTTP, the browser drops the cookie. Use HTTPS, or setLEAN_SESSION_SECURE=falsefor an intentional HTTP-only install. On HTTPS, set it totrue: it isn’t detected automatically. - Check the session cookie in the browser’s developer tools (Application → Cookies). It belongs only to the exact host you opened (for example
pm.example.com, notwww.pm.example.com). IfLEAN_APP_URLpoints to a different host than the one users type, Leantime’s redirects move them to that host and the cookie from the first one is lost. MakeLEAN_APP_URLthe address people actually use.
There’s No Password Field on the Login Page
Section titled “There’s No Password Field on the Login Page”Either LEAN_DISABLE_LOGIN_FORM=true is set, or the AdvancedAuth plugin’s Hide Login Form setting is on. See the AdvancedAuth plugin docs for how to turn it back on from the server.
Getting Help
Section titled “Getting Help”- Enable debug logging:
LEAN_DEBUG=1 - Check logs at
storage/logs/leantime-YYYY-MM-DD.log - Search GitHub Issues
- Ask in Discord #self-hosted channel
Was this page helpful?
Thanks, glad it helped.
Thanks for telling us. What was missing?
