What a SAML client is in Keycloak
In Keycloak, every app that signs users in through a realm is a client. A SAML client is a client whose protocol is saml. Keycloak acts as the SAML identity provider for it: it receives the app’s requests, signs the user in, and sends back signed assertions.
You can create a SAML client by hand in the admin console, by importing the app’s SAML metadata, or by importing a client representation in JSON. JSON is handy when you set up the same app in several realms or environments, or keep realm configuration in version control. This tool writes that JSON.
The client representation
Keycloak describes clients with a JSON structure called the client representation, the same one the admin REST API and realm exports use. For a SAML client, a few top-level fields matter, and most SAML settings live in the attributes map as strings.
{
"clientId": "https://app.example.com/saml/metadata",
"name": "Sample app",
"protocol": "saml",
"enabled": true,
"redirectUris": ["https://app.example.com/saml/acs"],
"frontchannelLogout": true,
"attributes": {
"saml_assertion_consumer_url_post": "https://app.example.com/saml/acs",
"saml_name_id_format": "username",
"saml.server.signature": "true",
"saml.assertion.signature": "false",
"saml.signature.algorithm": "RSA_SHA256",
"saml.client.signature": "true",
"saml.signing.certificate": "MIICsDCCAZgCCQ…"
}
}Each setting explained
Client id
For a SAML client, the client id is the app’s entity id: the exact Issuer value in the app’s requests. Keycloak looks up the client by it. A difference of one character, such as a trailing slash, means Keycloak does not recognize the app.
Assertion consumer service URL
saml_assertion_consumer_url_post is where Keycloak posts responses. The tool also puts the same URL in redirectUris, which Keycloak uses to check URLs an app sends in its requests.
Logout URL
saml_single_logout_service_url_post or saml_single_logout_service_url_redirect tells Keycloak where to send logout requests for single logout. With frontchannelLogout on, Keycloak sends them through the browser.
Name ID format
saml_name_id_format is username, email, persistent or transient. saml_force_name_id_format set to true makes Keycloak ignore the format the app asks for. See the NameID format reference.
Signatures
saml.server.signature: Sign documents. Keycloak signs the whole response.saml.assertion.signature: Sign assertions. Keycloak signs the assertion inside the response.saml.signature.algorithm:RSA_SHA256,RSA_SHA512or the oldRSA_SHA1.saml.client.signature: Client signature required. Keycloak refuses requests that are not signed with the app’s key.saml.signing.certificate: the app’s certificate, as one line of Base64, used to check those signatures.
Encryption and bindings
saml.encrypt with saml.encryption.certificate makes Keycloak encrypt assertions for the app. saml.force.post.binding makes Keycloak answer with HTTP-POST. saml.authnstatement includes the AuthnStatement with the session index, which apps need for single logout.
IdP-initiated sign-in
saml_idp_initiated_sso_url_name enables sign-in that starts at Keycloak. Users open https://<host>/realms/<realm>/protocol/saml/clients/<name> and land in the app signed in, without the app sending a request first.
What this tool does
Fill in the app’s details and choices; the tool writes the client JSON and the URLs to give the app: the realm metadata URL, the realm’s entity id and the SAML endpoint. It checks URLs, reads the certificates, and warns about risky choices such as signing nothing or using SHA-1.
It sets only the settings on the page. Everything else keeps Keycloak’s defaults when you import, and you can change any of it in the admin console afterwards.
What it does not do
It does not connect to Keycloak or create the client for you. It does not add protocol mappers for attributes, or client scopes. Add those in the console after import, or with the admin REST API.
How to import the client
- Fill in the form and copy the JSON into a file, for example
client.json. - In the Keycloak admin console, select the realm and open Clients.
- Choose Import client and load the file. Check the settings Keycloak shows, then save.
- Add mappers for the attributes the app needs, on the client’s dedicated scope.
- Give the app the realm metadata URL,
https://<host>/realms/<realm>/protocol/saml/descriptor. - Sign in through the app, and read the response with the SAML response decoder.
curl -X POST "https://auth.example.com/admin/realms/acme/clients" \
-H "Authorization: Bearer $ADMIN_TOKEN" \
-H "Content-Type: application/json" \
--data @client.jsonUse cases
Connecting a SaaS app
SaaS apps list their entity id and ACS URL on their SAML setup page. Enter them here, pick what the vendor says to sign, import the client, then paste the realm metadata URL or the SSO URL and certificate into the vendor’s page.
The same app in several environments
Staging and production apps usually have different entity ids and URLs. Generate one JSON per environment and keep the files with your other configuration, so each realm gets exactly the same settings.
An app that can only start sign-in at the identity provider
Some older apps cannot send an AuthnRequest. Set the IdP-initiated SSO URL name and give users that URL, for example as a bookmark or portal link.
Common errors after import
| What happens | Likely cause | Fix |
|---|---|---|
| Keycloak error page instead of sign-in | The request’s Issuer differs from the client id | Make the client id identical to the app’s entity id |
| Invalid requester | Client signature required, but the request is unsigned or signed with another key | Add the app’s current certificate under the client’s Keys tab, or check the app’s signing |
| App rejects the response signature | App checks the assertion signature, only the document is signed | Turn on Sign assertions |
| App cannot find the user | NameID format or value differs from what the app expects | Change the Name ID format, or force it |
| Logout does not reach the app | No logout URL, or front channel logout off | Set the logout URL and binding |
Security notes
- Always sign something. Unsigned responses can be forged.
- Require client signatures when the app can sign. It stops others from starting sign-in in the app’s name with changed parameters.
- Use RSA_SHA256 or stronger.
- Paste only the app’s public certificate. The private key stays with the app.
- Keep the ACS URL exact. Avoid wildcard redirect URIs.
Best practices
- Keep client JSON in version control and import it the same way in every environment.
- Name clients so people can tell them apart; the client id is a URL.
- Send only the attributes the app needs.
- Plan certificate rollovers on both sides before certificates expire.
Settings left to Keycloak’s defaults
The tool leaves out settings most apps do not need to change. You can set them in the admin console after import:
- Master SAML Processing URL, for apps that use one URL for every SAML endpoint.
- Canonicalization method for signatures. Exclusive canonicalization is the usual choice.
- SAML signature key name, which controls the key name Keycloak puts in signatures.
- Client scopes and protocol mappers, which decide the attributes in assertions.
- Login theme, consent and other settings shared with OpenID Connect clients.
When an app’s documentation names one of these, set it as documented. Otherwise the defaults are a reasonable start.
Checking the result
After import and the first sign-in, read the response with the SAML response decoder and check these points:
- Audience equals the client id.
- Destination and Recipient equal the ACS URL.
- A signature is present on the element the app checks.
- The NameID has the format and value the app expects.
- Every attribute the app needs is present, with the exact name.
If all five hold and the app still refuses, the problem is usually the app’s copy of Keycloak’s certificate or its clock.