Zum Hauptinhalt springen

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 at http://localhost:8000. Adjust for your deployment.
  • Keycloak: UI at http://localhost:8080/auth.
  • SP ACS URL and Entity ID: http://localhost:8000/api/acs.
Notiz

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.

Keycloak Realm hinzufügen

Keycloak Realm

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.

Keycloak-Client hinzufügen

Klicke auf Speichern. Diese Aktion erstellt den Client und bringt dich zum Tab Einstellungen.

Die folgenden sind Teil der Einstellungen:

  1. Name — e.g. Casdoor; any friendly name for the Keycloak UI.
  2. Aktiviert - Wähle on.
  3. Authn Statement einbeziehen - Wähle on.
  4. Dokumente signieren - Wähle on.
  5. Behauptungen signieren - Wähle off.
  6. Behauptungen verschlüsseln - Wähle off.
  7. Client-Signatur erforderlich - Wähle off.
  8. Name ID Format erzwingen - Wähle on.
  9. Name ID Format - Wähle username.
  10. Gültige Redirect URIs - Füge http://localhost:8000/api/acs hinzu.
  11. Master SAML Processing URL - http://localhost:8000/api/acs.
  12. Feinkörnige SAML-Endpunkt-Konfiguration
    1. Assertion Consumer Service POST Binding URL - http://localhost:8000/api/acs.
    2. Assertion Consumer Service Redirect Binding URL - http://localhost:8000/api/acs.

Die Konfiguration speichern.

Keycloak-Client konfigurieren

Tipp

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 KeysImportArchive FormatCertificate 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.

Metadaten herunterladen

Metadaten kopieren

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.

Tipp

If Client Signature Required is enabled in Keycloak and you uploaded a certificate, enable Sign request in Casdoor.

Casdoor-Anbieter

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.

Anbieter für App hinzufügen

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.

Casdoor-Login