Skip to content

Keycloak

Use a SAML client in a Keycloak realm. The preset uses the X500 attribute names of the Keycloak mappers.

The Keycloak preset fills in these attributes:

Field Attribute
Email Attribute urn:oid:1.2.840.113549.1.9.1
First Name Attribute urn:oid:2.5.4.42
Last Name Attribute urn:oid:2.5.4.4
Group Attribute Role

The import selects this preset when the IdP entity ID ends with /realms/<realm>.

Create the provider in Magento, and save it as inactive. Copy the SP Entity ID and the ACS URL from the Service Provider fieldset.

  1. In the Keycloak admin console, select the realm.

  2. Create a client of the type SAML.

  3. In Client ID, enter the SP Entity ID of Magento.

  4. Enter the ACS URL of Magento as the assertion consumer service POST binding URL.

  5. In Name ID format, select email.

  6. Make sure that Keycloak signs the assertions. Refer to the caution below.

  7. Add the X500 email, X500 givenName and X500 surname mappers to the client.

  8. Download the IdP metadata of the realm. The usual path is /realms/<realm>/protocol/saml/descriptor.

Keycloak setting Value
Client type SAML
Client ID SP Entity ID
Assertion Consumer Service POST Binding URL ACS URL
Name ID format email
Sign assertions On, unless Magento requires only a signed response
IdP metadata /realms/<realm>/protocol/saml/descriptor. Import this file in Magento.
Attribute name Source at Keycloak Note
urn:oid:1.2.840.113549.1.9.1 X500 email mapper Client mapper
urn:oid:2.5.4.42 X500 givenName mapper Client mapper
urn:oid:2.5.4.4 X500 surname mapper Client mapper
Role Role list mapper Default
member Group list mapper Optional. Replaces Role as the group attribute.

The attribute names must be exactly the same as in the Magento attribute mapping. To see the names that Keycloak sends, test the provider.

  1. Open the provider in Magento.

  2. Click Import Metadata, and select the metadata file of Keycloak.

  3. In Attribute Mapping > Load Preset, select Keycloak, if the import did not select it.

  4. Examine the imported values, and the note of the preset.

  5. In Your Password, enter your current admin password.

  6. Click Save and Continue Edit.

  7. Click Test Connection, and sign in with a test user.

  8. If the test succeeds, turn on Active, and save the provider again.

  9. Add and verify the domain of the users.

The default role list mapper sends the roles in the Role attribute. To map groups instead, add a Group list mapper. It sends the full group paths, such as /staff/admins, in the member attribute. Then set Group Attribute to member. For the role rules, refer to Role mapping.

Keycloak does not send the authentication methods over SAML. Thus the two-factor authentication of Magento applies. The exception is a step-up authentication that maps the level of a WebAuthn sign-in to the SmartcardPKI authentication context class.

Problem Solution
The login fails with “The assertion is not signed.” Keycloak signs only the response. Refer to the caution above.

For more problems, refer to Troubleshooting.