Skip to content

Keycloak SAML client generator

Generate a SAML client to import into a realm, from the app’s entity id, ACS URL, NameID format and signing choices.

Runs in your browser. Nothing you paste is sent to us.

The app (service provider)

It must match the Issuer the app puts in its requests, exactly.

A throwaway sample certificate is filled in. Public certificate only, never a private key.

Lets users start sign-in at Keycloak instead of at the app.

Client JSON

Keycloak client representation
{
  "clientId": "https://app.example.com/saml/metadata",
  "name": "Sample app",
  "protocol": "saml",
  "enabled": true,
  "baseUrl": "https://app.example.com/",
  "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_force_name_id_format": "false",
    "saml.server.signature": "true",
    "saml.assertion.signature": "false",
    "saml.signature.algorithm": "RSA_SHA256",
    "saml.client.signature": "true",
    "saml.force.post.binding": "true",
    "saml.authnstatement": "true",
    "saml.encrypt": "false",
    "saml_single_logout_service_url_post": "https://app.example.com/saml/logout",
    "saml.signing.certificate": "MIICsDCCAZgCCQDtTRSSC6cozzANBgkqhkiG9w0BAQsFADAaMRgwFgYDVQQDDA9hcHAuZXhhbXBsZS5jb20wHhcNMjYxMTI1MDkzNjE3WhcNMzYxMTIyMDkzNjE3WjAaMRgwFgYDVQQDDA9hcHAuZXhhbXBsZS5jb20wggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDann9gmucCTuKQRmAmmoxhF87YzxKUS/CvJU//4ViZYTJHOtFSz81wXQW3nc2DZW8tbN/2u3UswZQUYaHYu1In53rXDd5gcDeN7/o9hcAhYTIMltIcJyM4OM/h/FEOoMF6dvTDjleO8P5u95sKqWrXiRhTtGKuqS2uK7mDJSCj1MSn3UExYkTkb6f6nbza94f9ArWtTktb3ZR7z/j7bPJPj0cOKLZ3vsP97kCWO7CIDZM1OANBJBy2cZ/N8TYWWPBzVL01TEg2/+aWBF5tm6qQaI+nP9pzKppsebgrLZCyRk7FFud+k9NTIzPrqrxinTq48/V8FXk7WzK7hC/C+f07AgMBAAEwDQYJKoZIhvcNAQELBQADggEBAJVdGUKJlxZAxJRN26eH+LB3rmyPsZXqM/DDGsCbRPsXCMPlDKhEC3qhohu+BgmvLjEuoJZO4qkf2a/4ay9iRPC+uQbUwMmXGvG+tsdZlyliZ+p646ARHRTC1aUGa80G274vqXp4hUuKOJ9DPvYt3uX9oF6g9JQXx69m4+QoA3XaTvN2L6oT37FvjNhe9nEn4laRd6Wg+zn40Be3omy/0eFMBgHYJ7WtHCvYQ1peWBwyupGjSXoMWIX1pZ2eBBdbHXQZivHvrwphqDqw9pdkWmXo9IiEJTBkkPvyS/vw3c2RaWvcU9EWI6Xbv5IhSoYLdJNypSG+JY97ffEHFcTSj3s="
  }
}
In the admin console open Clients, choose Import client, and load this file. Settings left out keep Keycloak’s defaults.

What to give the app

IdP metadata
https://auth.example.com/realms/acme/protocol/saml/descriptormost apps can read this URL
IdP entity id
https://auth.example.com/realms/acme
SSO and logout URL
https://auth.example.com/realms/acme/protocol/saml

How to use it

  1. Enter the app’s entity id (it becomes the client id) and its assertion consumer service URL.
  2. Pick the Name ID format and what Keycloak signs.
  3. If the app signs its requests, keep Client signature required on and paste the app’s certificate.
  4. Copy the JSON and import it: Clients, then Import client, in the admin console.
  5. Give the app the realm’s metadata URL shown under the JSON.

What to know

A Keycloak SAML client is a client with protocol saml. Its client id must equal the app’s entity id, the Issuer the app puts in its requests. The SAML settings live in the client’s attributes, such as saml_assertion_consumer_url_post and saml.signature.algorithm.

Sign documents signs the whole response; Sign assertions signs the assertion inside it. Apps differ in which they check, so read the app’s documentation. Client signature required makes Keycloak reject requests the app did not sign with the certificate you give.

The JSON sets only the settings on this page. Everything else keeps Keycloak’s defaults, and you can change any of it in the console after import.

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.

Generated client (sample, shortened)
{
  "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_SHA512 or the old RSA_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

  1. Fill in the form and copy the JSON into a file, for example client.json.
  2. In the Keycloak admin console, select the realm and open Clients.
  3. Choose Import client and load the file. Check the settings Keycloak shows, then save.
  4. Add mappers for the attributes the app needs, on the client’s dedicated scope.
  5. Give the app the realm metadata URL, https://<host>/realms/<realm>/protocol/saml/descriptor.
  6. Sign in through the app, and read the response with the SAML response decoder.
Or with the admin REST API
curl -X POST "https://auth.example.com/admin/realms/acme/clients" \
  -H "Authorization: Bearer $ADMIN_TOKEN" \
  -H "Content-Type: application/json" \
  --data @client.json

Use 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 happensLikely causeFix
Keycloak error page instead of sign-inThe request’s Issuer differs from the client idMake the client id identical to the app’s entity id
Invalid requesterClient signature required, but the request is unsigned or signed with another keyAdd the app’s current certificate under the client’s Keys tab, or check the app’s signing
App rejects the response signatureApp checks the assertion signature, only the document is signedTurn on Sign assertions
App cannot find the userNameID format or value differs from what the app expectsChange the Name ID format, or force it
Logout does not reach the appNo logout URL, or front channel logout offSet 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.

Questions

Frequently asked questions

How do I create a SAML client in Keycloak?

In the admin console, open Clients and choose Create client with type SAML, or Import client to load JSON or the app’s metadata. The client id must equal the app’s entity id.

What should the client id of a Keycloak SAML client be?

The app’s SAML entity id, exactly as it appears in the Issuer of the app’s requests. Keycloak uses it to find the client.

Should I turn on Sign documents or Sign assertions?

Sign at least one. Many apps check the assertion signature; some check only the response. If the app’s documentation does not say, signing both is the safe choice.

What does Client signature required do?

Keycloak then accepts only requests signed with the app’s key, whose certificate is stored on the client. Unsigned or wrongly signed requests are refused.

Where is the Keycloak SAML metadata URL for an app?

https://<host>/realms/<realm>/protocol/saml/descriptor. It holds the realm’s entity id, endpoints and signing certificate.

How do I set up IdP-initiated SSO in Keycloak?

Set the client’s IDP-Initiated SSO URL name. Users then start sign-in at https://<host>/realms/<realm>/protocol/saml/clients/<name>.

Why does Keycloak say Invalid requester?

Usually the request’s signature could not be verified: the client requires signatures and the request is unsigned, or it was signed with a key whose certificate Keycloak does not have.

Can I import a SAML client with the admin REST API?

Yes. POST the client representation to /admin/realms/<realm>/clients with an admin access token.

Which signature algorithm should a Keycloak SAML client use?

RSA_SHA256 unless the app needs something else. RSA_SHA512 also works with most apps. Use RSA_SHA1 only for an old app that cannot verify anything stronger.

Why does the app receive no attributes from Keycloak?

A SAML client sends only the attributes its mappers produce. Add a mapper for each attribute the app needs on the client’s dedicated scope, with the exact attribute name the app expects.

Rather not run Keycloak yourself?

We run it for you on a cluster of your own, with backups, upgrades and written support. Starter and Premium begin with a 7-day trial.