Keycloak
Allows users to authenticate using their Keycloak credentials by configuring Keycloak as a federated identity provider via SAML.
Preparation
The following placeholders are used in this guide:
authentik.companyis the FQDN of the authentik installation.keycloak.companyis the FQDN of the Keycloak installation.keycloak-slugis the slug you will assign to the SAML source in authentik (e.g.,keycloak).
Export certificates
Before configuring either service, you need to export the signing certificates from both Keycloak and authentik. Each service needs the other's public certificate to verify signatures and handle SAML encryption.
Export the Keycloak signing certificate
- Log in to Keycloak as an administrator.
- Navigate to Realm settings > Keys.
- Find the RSA key with Use set to
SIG. - Click Certificate to copy the certificate value.
- Save the certificate in the following format:
-----BEGIN CERTIFICATE-----
<Copied Keycloak Public Key Certificate Content>
-----END CERTIFICATE-----
Export the authentik signing certificate
- Log in to authentik as an administrator and open the authentik Admin interface.
- Navigate to System > Certificates.
- Click the certificate you plan on using for signing (e.g., the default
authentik Self-signed Certificate). - Click Download Certificate.
Keycloak configuration
Create a SAML client in Keycloak
- Log in to Keycloak as an administrator.
- Navigate to Clients and click Create client.
- Configure the client with the following settings:
- Set Client type to
SAML. - Set Client ID to
https://authentik.company/source/saml/<keycloak-slug>/metadata/.
- Set Client type to
- Click Next.
- Configure the following settings:
- Set Valid redirect URIs to
https://authentik.company/source/saml/<keycloak-slug>/acs/. - Set Master SAML Processing URL to
https://authentik.company/source/saml/<keycloak-slug>/acs/. - Set Root URL to
https://authentik.company.
- Set Valid redirect URIs to
- Click Save.
Configure signing and encryption
- Navigate to the Settings tab and scroll to Signature and Encryption.
- Configure the following settings:
- Enable Sign documents.
- Enable Sign assertions.
- Enable Encrypt assertions.
Upload the authentik certificate to Keycloak
- In the Keycloak Admin console, navigate to Clients and click the SAML client you created earlier.
- Navigate to the Keys tab.
- Configure the following settings:
- Enable Client signature required.
- Click Import and upload the authentik certificate you exported earlier. This allows Keycloak to verify signatures on requests from authentik.
- Enable Encrypt assertions.
- Click Import under the encryption key and upload the authentik certificate.
authentik configuration
Upload the Keycloak certificate to authentik
- Log in to authentik as an administrator and open the authentik Admin interface.
- Navigate to System > Certificates and click Import.
- Give it a name like
Keycloak Signing Certificate. - Paste the Keycloak certificate you exported earlier into the Certificate field.
- Leave the Private Key field empty.
- Click Create.
Create a SAML source in authentik
- Navigate to Directory > Federation and Social login and click Create.
- Select SAML Source and configure the following settings:
- Set Name to
Keycloak. - Set Slug to
keycloak. - Set SSO URL to
https://keycloak.company/realms/<realm-name>/protocol/saml. - Set SLO URL to
https://keycloak.company/realms/<realm-name>/protocol/saml. - Set Issuer to
https://authentik.company/source/saml/<keycloak-slug>/metadata/. - Set Service Provider Binding to
Post (Auto-Submit). - Set Signing Keypair to an authentik certificate (e.g., the default
authentik Self-signed Certificate). - Set Verification Certificate to the Keycloak certificate you uploaded earlier.
- Enable Verify assertion signature.
- Enable Verify response signature.
- Set Encryption Certificate to an authentik certificate (e.g., the default
authentik Self-signed Certificate).
- Set Name to
- Click Finish.
Display new source on login screen
For instructions on how to display the new source on the authentik login page, refer to the Add sources to default login page documentation.
Embed new source in flow Enterprise
For instructions on embedding the new source within a flow, such as an authorization flow, refer to the Source Stage documentation.
Troubleshooting
- Signature verification failed: Ensure the correct certificates are configured on both sides. Each side needs the other's signing certificate for verification.
- Encryption errors: Ensure the encrypting party has the other party's public certificate, and the decrypting party has their own private key.