Integrate with Keycloak
Support level: Community
What is Keycloak
Keycloak is an open-source Identity and Access Management (IAM) platform. It can be used both as an Identity Provider and as an application.
Preparation
The following placeholders are used in this guide:
keycloak.companyis the FQDN of the Keycloak installation.authentik.companyis the FQDN of the authentik installation.
This documentation lists only the settings that you need to change from their default values. Be aware that any changes other than those explicitly mentioned in this guide could cause issues accessing your application.
Configuration methods
Keycloak can be configured to use either OIDC or SAML for federated login sources. This guide covers both methods.
- Log in with OIDC
 - Log in with SAML
 
authentik configuration
To support the integration of Keycloak with authentik, you need to create an application/provider pair in authentik.
Create an application and provider in authentik
- 
Log in to authentik as an administrator and open the authentik Admin interface.
 - 
Navigate to Applications > Applications and click Create with Provider to create an application and provider pair. (Alternatively you can first create a provider separately, then create the application and connect it with the provider.)
- Application: provide a descriptive name, an optional group for the type of application, the policy engine mode, and optional UI settings.
 - Choose a Provider type: select OAuth2/OpenID Connect as the provider type.
 - Configure the Provider: provide a name (or accept the auto-provided name), the authorization flow to use for this provider, and the following required configurations.
- Note the Client ID, Client Secret, and slug values because they will be required later.
 - Set a 
Strictredirect URI tohttps://keycloak.company/access/oidc/callback. - Set the Logout URI to 
https://keycloak.company/realms/<keycloak-realm-name>/protocol/openid-connect/logout/backchannel-logout. - Set the Logout Method to 
Back-channel. - Select any available signing key.
 
 - Configure Bindings (optional): you can create a binding (policy, group, or user) to manage the listing and access to applications on a user's My applications page.
 
 - 
Click Submit to save the new application and provider.
 
Keycloak configuration
- 
Log in to Keycloak as an administrator.
 - 
Navigate to Configure > Identity Providers, click OpenID Connect v1.0 and set the following fields:
- Discovery URL: 
https://authentik.company/application/o/<slug>/.well-known/openid-configuration - Client ID: enter the client ID from authentik.
 - Client secret: enter the client secret from authentik.
 
 - Discovery URL: 
 - 
Click Submit.
 
authentik configuration
To support the integration of Keycloak with authentik, you need to create an application/provider pair in authentik.
Create an application and provider in authentik
- Log in to authentik as an administrator and open the authentik Admin interface.
 - Navigate to Applications > Applications and click Create with Provider to create an application and provider pair. (Alternatively you can first create a provider separately, then create the application and connect it with the provider.)
- Application: provide a descriptive name, an optional group for the type of application, the policy engine mode, and optional UI settings. Take note of the slug as it will be required later.
 - Choose a Provider type: select SAML Provider as the provider type.
 - Configure the Provider: provide a name (or accept the auto-provided name), the authorization flow to use for this provider, and the following required configurations.
- Note the slug value because it will be required later.
 - Set the ACS URL to 
https://keycloak.company/realms/<keycloak-realm-name>/broker/saml/endpoint. - Set the Issuer to 
authentik. - Set the Service Provider Binding to 
Post. - Set the SLS URL to 
https://keycloak.company/realms/<keycloak-realm-name>/broker/saml/endpoint. - Set the SLS Binding to 
Post. - Set the Logout Method to 
Back-channel (POST). - Set the Audience to 
https://keycloak.company/realms/<keycloak-realm-name>. - Under Advanced protocol settings, set Signing Certificate to use any available certificate.
 
 
 
- Configure Bindings (optional): you can create a binding (policy, group, or user) to manage the listing and access to applications on a user's My applications page.
 
- Click Submit to save the new application and provider.
 
Keycloak configuration
- Log in to Keycloak as an administrator.
 - Navigate to Configure > Identity Providers and click SAML v2.0.
 - Set the Service provider entity ID to 
https://authentik.company/application/saml/<slug>/metadata/ - Click Submit.
 
Configuration verification
To ensure that authentik is correctly integrated with Keycloak, log out and then log back in by clicking SAML or OIDC on the login screen. You should be redirected to authentik to log in, and if the process is successful, you'll be taken to the Keycloak dashboard.