Keycloak SAML
Keycloak is an open-source IdP that supports SAML and OpenID Connect and can broker LDAP or other SAML IdPs. This guide configures a Keycloak SAML client and Casdoor so Keycloak users can sign in to Casdoor.
Keycloak konfigurieren
Example assumptions:
- Casdoor: UI at
http://localhost:7001, API athttp://localhost:8000. Adjust for your deployment. - Keycloak: UI at
http://localhost:8080/auth. - SP ACS URL and Entity ID:
http://localhost:8000/api/acs.
The /api/acs endpoint only accepts POST requests. Ensure Keycloak is configured to use HTTP POST binding for SAML responses.
Use the default realm or create a new one.


Einen Client-Eintrag in Keycloak hinzufügen
Klicke im Menü auf Clients und dann auf Erstellen, um zur Seite Client hinzufügen zu gelangen. Fülle die Felder wie folgt aus:
- Client ID:
http://localhost:8000/api/acs- Dies wird die SP Entity ID sein, die später in der Casdoor-Konfiguration verwendet wird. - Client-Protokoll:
saml. - Client SAML Endpoint:
http://localhost:8000/api/acs- Diese URL ist der Ort, an den der Keycloak-Server SAML-Anfragen und -Antworten senden soll. In der Regel haben Anwendungen eine URL zur Verarbeitung von SAML-Anfragen. Mehrere URLs können im Einstellungstab des Clients festgelegt werden.

Klicke auf Speichern. Diese Aktion erstellt den Client und bringt dich zum Tab Einstellungen.
Die folgenden sind Teil der Einstellungen:
- Name — e.g.
Casdoor; any friendly name for the Keycloak UI. - Aktiviert - Wähle
on. - Authn Statement einbeziehen - Wähle
on. - Dokumente signieren - Wähle
on. - Behauptungen signieren - Wähle
off. - Behauptungen verschlüsseln - Wähle
off. - Client-Signatur erforderlich - Wähle
off. - Name ID Format erzwingen - Wähle
on. - Name ID Format - Wähle
username. - Gültige Redirect URIs - Füge
http://localhost:8000/api/acshinzu. - Master SAML Processing URL -
http://localhost:8000/api/acs. - Feinkörnige SAML-Endpunkt-Konfiguration
- Assertion Consumer Service POST Binding URL -
http://localhost:8000/api/acs. - Assertion Consumer Service Redirect Binding URL -
http://localhost:8000/api/acs.
- Assertion Consumer Service POST Binding URL -
Die Konfiguration speichern.

To sign the authn request: enable Client Signature Required and upload your certificate. Casdoor’s private key and certificate (token_jwt_key.key, token_jwt_key.pem) are in the object directory. In Keycloak open Keys → Import → Archive Format → Certificate PEM and upload the certificate.
Klicke auf den Tab Installation.
For Keycloak <= 5.0.0, select Format Option - SAML Metadata IDPSSODescriptor and copy the metadata.
Für Keycloak 6.0.0+, wähle Formatoption - Mod Auth Mellon Dateien und klicke auf Herunterladen. Entpacke die heruntergeladene .zip, finde idp-metadata.xml und kopiere die Metadaten.


In Casdoor konfigurieren
Einen neuen Anbieter in Casdoor erstellen.
Wähle die Kategorie als SAML, Typ als Keycloak. Kopiere den Inhalt der Metadaten und füge ihn in das Feld Metadaten ein. Die Werte von Endpunkt, IdP und Aussteller-URL werden automatisch generiert, nachdem du auf die Schaltfläche Parse klickst. Klicke abschließend auf die Schaltfläche Speichern.
If Client Signature Required is enabled in Keycloak and you uploaded a certificate, enable Sign request in Casdoor.

Bearbeite die Anwendung, die du in Casdoor konfigurieren möchtest. Wähle den Anbieter, den du gerade hinzugefügt hast, und klicke auf die Schaltfläche Speichern.

Test
Open the application’s login page; a Keycloak option appears. Click it to sign in via Keycloak; after success you are logged into Casdoor.
