Keycloak SSO for Portainer
Sign in to Portainer with Keycloak through its Custom OAuth provider, with user provisioning and, in Business Edition, teams from a groups claim.
Portainer signs users in with Keycloak through the Custom OAuth provider. The Portainer server exchanges the authorization code with Keycloak and reads the user from Keycloak's userinfo endpoint, so the client is confidential and has a secret.
Checked against the Portainer 2.45 LTS docs, the Portainer CE 2.45.4 source and Keycloak 26.8 on 25 November 2026.
Replace auth.example.com with your RealmDeploy hostname and acme with your realm. The examples use https://portainer.example.com for Portainer. If users reach Portainer on its own port, for example https://portainer.example.com:9443, use that address everywhere below.
Community Edition or Business Edition
OAuth sign-in with the Custom provider and automatic user provisioning work in both editions. In Portainer CE these switches are Business Edition features and cannot be turned on:
- Hide internal authentication prompt
- Automatic team membership, with Claim name and Statically assigned teams
- The preset Microsoft, Google and GitHub providers
In CE, put new users in one Default team and manage other team memberships by hand.
In Keycloak
Create the client
Open Clients, choose Create client, and use these values:
| Setting | Value |
|---|---|
| Client type | OpenID Connect |
| Client ID | portainer |
| Client authentication | On |
| Authentication flow | Standard flow only |
| Root URL | https://portainer.example.com |
| Home URL | https://portainer.example.com |
| Valid redirect URIs | https://portainer.example.com/ |
| Valid post logout redirect URIs | https://portainer.example.com/ |
| Web origins | Leave empty. Portainer talks to Keycloak from its server, not from the browser. |
Choose Save, then copy the secret from the Credentials tab.
Portainer sends its Redirect URL setting as the redirect_uri, unchanged, so the value in Keycloak must match it character for character, trailing slash included.
Add a groups claim (Business Edition)
Only needed for automatic team membership. Portainer reads the claim from the userinfo response.
- On the
portainerclient, open the Client scopes tab and chooseportainer-dedicated. - Choose Configure a new mapper and pick Group Membership.
- Fill it in and choose Save:
| Field | Value |
|---|---|
| Name | groups |
| Token Claim Name | groups |
| Full group path | Off |
| Add to ID token | Off |
| Add to access token | Off |
| Add to userinfo | On |
In Portainer
Open Settings → Authentication, choose OAuth under Authentication method, and select the Custom provider.
Single sign-on and provisioning:
| Field | Value |
|---|---|
| Use SSO | On, so users with a Keycloak session are not asked for their password again |
| Automatic user provisioning | On, so Portainer creates users at first sign-in with the standard user role |
| Default team | Optional. The team new users join. |
OAuth Configuration:
| Field | Value |
|---|---|
| Client ID | portainer |
| Client secret | The secret from the Credentials tab |
| Authorization URL | https://auth.example.com/realms/acme/protocol/openid-connect/auth |
| Access token URL | https://auth.example.com/realms/acme/protocol/openid-connect/token |
| Resource URL | https://auth.example.com/realms/acme/protocol/openid-connect/userinfo |
| Redirect URL | https://portainer.example.com/ |
| Logout URL | https://auth.example.com/realms/acme/protocol/openid-connect/logout?client_id=portainer&post_logout_redirect_uri=https%3A%2F%2Fportainer.example.com%2F |
| User identifier | preferred_username |
| Scopes | openid profile email |
| Auth Style | Auto Detect |
Choose Save settings.
What the settings do:
| Setting | Meaning |
|---|---|
| Resource URL | Portainer calls Keycloak's userinfo endpoint with the access token and reads the user from the response. |
| User identifier | The userinfo field that becomes the Portainer username. preferred_username is the Keycloak username; email also works. |
| Use SSO | When off, Portainer adds prompt=login and Keycloak asks for the password every time. |
| Logout URL | Portainer sends the browser here after logout. Keycloak ends the session and returns the user to post_logout_redirect_uri, which must be in Valid post logout redirect URIs. Portainer sends no id_token_hint, so Keycloak asks the user to confirm. |
Build or check the logout address with the logout URL builder.
The initial admin account, the first user created in Portainer, can still sign in with its local password, and Portainer does not send it to the Logout URL. Keep that password as your way back in if OAuth breaks.
Groups and roles
Business Edition. Under Team membership:
| Field | Value |
|---|---|
| Automatic team membership | On |
| Claim name | groups |
| Statically assigned teams | Choose add team mapping, enter a claim value regex such as ^portainer-devs$ and pick the Portainer team. Add one mapping per team. |
| Default team | The team for users who match no mapping. |
Create the teams in Portainer first under User-related → Teams, then give each team access to its environments. Business Edition can also give admin rights to members of chosen groups; see Portainer's OAuth page for that option.
Community Edition. Team membership does not come from Keycloak. Users who sign in are created with the standard user role and join the Default team if you set one. Add them to other teams under User-related → Teams, and make administrators under User-related → Users with the Administrator toggle.
Test it
- Open
https://portainer.example.comin a private window and choose Login with OAuth. - Sign in to Keycloak as a test user. Portainer creates the user and signs them in.
- To see what Portainer receives, open the
portainerclient in Keycloak, go to Client scopes → Evaluate, pick the user and look at Generated user info.preferred_usernameand, for team membership,groupsmust be there. - Log out of Portainer. Keycloak asks you to confirm, then returns you to Portainer.
Common errors
| Error | Cause | Fix |
|---|---|---|
Invalid parameter: redirect_uri on the Keycloak page | Portainer's Redirect URL differs from Valid redirect URIs, often by a trailing slash or a port. | Make both exactly https://portainer.example.com/. Compare them with the redirect URI matcher. |
| Portainer shows an OAuth error after Keycloak login | Wrong client secret, Client authentication off, or a wrong Access token URL. | Copy the secret again and check the URLs. Look up returned codes in the OAuth error lookup. |
| Sign-in fails with no user created | User identifier names a field that is not in the userinfo response, or openid is missing from Scopes. | Use preferred_username and keep openid profile email. Check Generated user info in Keycloak. |
| Sign-in fails for new users | Automatic user provisioning is off. | Turn it on, or create the users in Portainer first with the same username. |
| Users land in no team (Business Edition) | The groups claim is missing from userinfo, Full group path is on, or no regex matches. | Turn on Add to userinfo, turn off Full group path, and test the regex against the group names. |
Invalid redirect uri on logout | The post_logout_redirect_uri in Logout URL is not in Valid post logout redirect URIs, or it is not URL-encoded. | Add https://portainer.example.com/ to the client and encode it in the URL. |
FAQ
Does Portainer use OpenID Connect discovery?
No. The Custom provider takes the three endpoints separately. Copy them from your realm's discovery document at https://auth.example.com/realms/acme/.well-known/openid-configuration, or from the Keycloak realm endpoints tool.
Do I need to ask you to open a connection?
No. Portainer calls Keycloak's token and userinfo endpoints, which are public on your hostname, and logout runs through the browser. Keycloak never calls Portainer.
Can users skip the Portainer login page?
Hiding the internal login form, with Hide internal authentication prompt, is a Business Edition feature. In CE the login page shows both the local form and the OAuth button.
Sources
- Portainer, Authenticate via OAuth: https://docs.portainer.io/admin/settings/authentication/oauth
- Portainer, Teams and Turn a user into an administrator: https://docs.portainer.io/admin/user/teams and https://docs.portainer.io/admin/user/promote
- Portainer CE 2.45.4 release: https://github.com/portainer/portainer/releases/tag/2.45.4
- Portainer CE source, OAuth settings form and Business Edition limits: https://github.com/portainer/portainer/blob/2.45.4/app/portainer/oauth/components/oauth-settings/oauth-settings.html
- Portainer CE source, feature flags: https://github.com/portainer/portainer/blob/2.45.4/app/react/portainer/feature-flags/feature-flags.service.ts
- Portainer CE source, login URL and SSO prompt: https://github.com/portainer/portainer/blob/2.45.4/api/http/handler/settings/settings_public.go
- Portainer CE source, logout redirect: https://github.com/portainer/portainer/blob/2.45.4/app/portainer/views/logout/logoutController.js
- Keycloak Server Administration Guide, client settings, protocol mappers and RP-initiated logout: https://www.keycloak.org/docs/latest/server_admin/
Keycloak SSO for Nextcloud
Sign in to Nextcloud with Keycloak through the official OpenID Connect user backend app (user_oidc), with group provisioning and logout from both.
Connect Microsoft Entra ID to Keycloak (OIDC)
Let users sign in to your Keycloak realm with their Microsoft Entra ID work account over OpenID Connect, and map Entra groups to Keycloak groups.