---
title: Integrate with Keycloak
sidebar_label: Keycloak
support_level: community
---

import TabItem from "@theme/TabItem";
import Tabs from "@theme/Tabs";

## 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.
>
> -- https://keycloak.org

## Preparation

The following placeholders are used in this guide:

- `keycloak.company` is the FQDN of the Keycloak installation.
- `authentik.company` is the FQDN of the authentik installation.

:::info
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.

<Tabs
  defaultValue="oidc"
  values={[
    { label: "Log in with OIDC", value: "oidc" },
    { label: "Log in with SAML", value: "saml" },
  ]}>
  <TabItem value="oidc">

## 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

1. Log in to authentik as an administrator and open the authentik Admin interface.
2. 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 `Strict` redirect URI to `https://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](/docs/add-secure-apps/bindings-overview/) (policy, group, or user) to manage the listing and access to applications on a user's **My applications** page.

3. Click **Submit** to save the new application and provider.

## Keycloak configuration

1. Log in to Keycloak as an administrator.
2. 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.

3. Click **Submit**.

  </TabItem>
  <TabItem value="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

1. Log in to authentik as an administrator and open the authentik Admin interface.
2. 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](/docs/add-secure-apps/bindings-overview/) (policy, group, or user) to manage the listing and access to applications on a user's **My applications** page.

3. Click **Submit** to save the new application and provider.

## Keycloak configuration

1. Log in to Keycloak as an administrator.
2. Navigate to **Configure** > **Identity Providers** and click **SAML v2.0**.
3. Set the **Service provider entity ID** to `https://authentik.company/application/saml/<slug>/metadata/`
4. Click **Submit**.

  </TabItem>
</Tabs>

## 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.

## Resources

- [Keycloak Docs — Managing OpenID Connect and SAML Clients](https://www.keycloak.org/docs/latest/server_admin/index.html#assembly-managing-clients_server_administration_guide)
- [Keycloak Docs — Configuring Realms](https://www.keycloak.org/docs/latest/server_admin/index.html#_configuring-realms)
