Skip to content

SAML redirect binding URL builder

Build an HTTP-Redirect binding URL from SAML XML or an encoded value, the identity provider’s endpoint and a RelayState.

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

Message

The sample Keycloak realm’s SAML endpoint is filled in: https://<host>/realms/<realm>/protocol/saml.

A sample AuthnRequest is filled in. It is deflated and Base64-encoded here.

Sent back unchanged with the response; apps use it for the page to return to.

Redirect URL

URL
 
The URL is not signed. An identity provider that wants signed requests, such as a Keycloak client with Client signature required, needs SigAlg and a Signature over the query string, made with the app’s private key.

How to use it

  1. Enter the identity provider’s single sign-on URL.
  2. Paste the request XML, or a value that is already deflated and Base64-encoded.
  3. Add a RelayState if the app needs one back.
  4. Copy the URL and open it to test the request.

What to know

The redirect binding sends a SAML message in the URL: the XML is compressed with raw DEFLATE, Base64-encoded and URL-encoded into a SAMLRequest or SAMLResponse parameter, with RelayState after it.

A Keycloak realm takes SAML requests at https://<host>/realms/<realm>/protocol/saml. If the client has Client signature required on, the URL also needs SigAlg and a Signature parameter made with the app’s private key; this tool leaves them out.

The binding limits RelayState to 80 bytes. Store anything longer on the app’s side and send a short key.

What the HTTP-Redirect binding is

The HTTP-Redirect binding is one of the ways SAML 2.0 moves a message between two parties through the browser. It is defined in section 3.4 of the bindings specification. The sender puts the message in a URL and redirects the browser there with an HTTP 302 or 303 response, or a plain link.

It is the usual way an app starts sign-in: the user clicks sign in, and the app redirects them to the identity provider with an AuthnRequest in the URL. It is also used for logout requests and responses. It is not used for sign-in responses, which are too large for a URL and travel with HTTP-POST instead.

What goes in the URL

Redirect binding URL (sample, shortened)
https://auth.example.com/realms/acme/protocol/saml
  ?SAMLRequest=fZJBT8MwDIXv%2BxVR7m26IkBEa6WyCVFpQMUG…
  &RelayState=%2Fdashboard
  &SigAlg=http%3A%2F%2Fwww.w3.org%2F2001%2F04%2Fxmldsig-more%23rsa-sha256
  &Signature=Qm9ndXMgc2FtcGxlIHNpZ25hdHVyZQ…
ParameterMeaning
SAMLRequest or SAMLResponseThe XML, raw-DEFLATE compressed, Base64-encoded and URL-encoded
RelayStateOptional. An opaque value the other side sends back unchanged, at most 80 bytes
SigAlgOnly when signed. The signature algorithm URI
SignatureOnly when signed. Base64 signature over the other parameters

If the endpoint URL already has a query string, the SAML parameters are added to it. The identity provider reads them from the query, not from the path.

RelayState

RelayState lets the app remember something across the sign-in round trip, typically the page the user wanted before they were asked to sign in. The identity provider returns it with the response, untouched.

The bindings specification limits it to 80 bytes and says the sender should protect its integrity. In practice, apps store the real target on their side and send a short random key, then look the key up when the response arrives. Putting a full URL in RelayState and redirecting to it without checking is an open redirect.

In IdP-initiated sign-in there is no request, but a RelayState can still travel with the response. Keycloak lets you set one per SAML client, the IDP Initiated SSO Relay State, which the app can use to decide where to send the user.

How a redirect URL is signed

The XML of a redirect message carries no ds:Signature. Instead, the sender builds this exact string from the URL-encoded values, in this order and without any parameter that is absent:

SAMLRequest=<value>&RelayState=<value>&SigAlg=<value>

It signs the string with its private key, Base64-encodes the signature, URL-encodes that, and appends it as Signature. The receiver rebuilds the string from the parameters exactly as they arrived in the URL and checks the signature with the sender’s certificate.

Because the signature covers the URL-encoded bytes, decoding and re-encoding the values on either side can change them and break the check, for example when one side encodes a character in lowercase hex and the other in uppercase.

What this tool does

Enter the identity provider’s endpoint, choose SAMLRequest or SAMLResponse, paste the message XML or an already encoded value, and add a RelayState. The tool deflates and encodes the XML, or checks that the encoded value inflates, then builds the full URL. It shows the URL length and the RelayState size, and warns when RelayState is over 80 bytes, when the parameter name does not match the message type, or when the XML still contains a signature.

Switching between XML and encoded value carries the message across, so you can move between the two forms.

What it does not do

It does not sign the URL. Signing needs the app’s private key, and the page does not ask for keys. If the identity provider requires signed requests, the URL from this tool will be refused, and the page says so. It does not open the URL or send anything; you copy it and open it yourself.

How to use it

  1. Find the identity provider’s single sign-on URL for the redirect binding in its metadata, for example with the SAML metadata viewer.
  2. Enter it as the endpoint.
  3. Paste an AuthnRequest whose Issuer is the app’s entity id and whose Destination is the endpoint. Start from the sample and change the URLs.
  4. Add a RelayState if you want to test that it comes back.
  5. Copy the URL and open it in a private browser window.
  6. After sign-in, capture the response and read it with the SAML response decoder.

Use cases

Testing a new SAML client before the app is ready

When you register an app at an identity provider, a hand-built URL shows whether the identity provider accepts requests in the app’s name. If you see the sign-in page, the issuer and destination are right. Errors at this step are about the client registration, not the app.

Testing Keycloak as the identity provider

A Keycloak realm accepts redirect requests at https://<host>/realms/<realm>/protocol/saml. The Issuer must match the client id of a SAML client in the realm. If that client has Client signature required on, Keycloak refuses an unsigned URL; for a manual test, use a test client with the setting off, never a production one.

Reproducing a user’s problem

Decode the request from a failing sign-in with the SAML request decoder, change one thing, such as the NameID policy or ForceAuthn, rebuild the URL here and try again. This isolates which part of the request causes the error.

Starting logout

A LogoutRequest can be sent the same way. It needs the user’s NameID and session index from the assertion, and most identity providers require logout requests to be signed.

Common problems

  • The identity provider cannot inflate the request: it was compressed with zlib or gzip instead of raw DEFLATE.
  • The identity provider does not know the app: the Issuer differs from the registered entity id.
  • The signature is rejected: the string was signed with values decoded or in another order, or with the wrong key.
  • The URL is too long for a proxy or server: the message is large; use the POST binding.
  • RelayState is lost or cut: it is over 80 bytes, or contains characters that were not URL-encoded.

Security notes

  • URLs end up in browser history, proxy logs and analytics. Never put secrets or personal data in a SAML request or in RelayState.
  • Validate RelayState on return. Do not redirect to whatever it contains.
  • Identity providers should require signed requests from apps that can sign, and must send responses only to registered ACS URLs.

Building the URL in code

The same steps in a few lines of Node.js, for when you script tests:

Node.js (no signature)
const fs = require('node:fs');
const zlib = require('node:zlib');
const xml = fs.readFileSync('request.xml');
const value = zlib.deflateRawSync(xml).toString('base64');
const url = new URL('https://auth.example.com/realms/acme/protocol/saml');
url.searchParams.set('SAMLRequest', value);
url.searchParams.set('RelayState', '/dashboard');
console.log(url.toString());

URLSearchParams encodes spaces as +, which is fine for unsigned requests because Base64 never contains spaces. For signed requests, build the query string yourself with encodeURIComponent, so the bytes you sign are exactly the bytes you send.

Redirect or POST for requests

HTTP-RedirectHTTP-POST
How the browser gets thereA redirect or a linkAn auto-submitting form
CompressionRaw DEFLATENone
Size limitPractical URL limitsNone in practice
SignatureSeparate Signature parameterds:Signature inside the XML
Visible in logs and historyYes, in the URLLess so, in the request body

For an AuthnRequest, redirect is the common choice because it is simple and the request is small. Use POST when the request is large, or when the identity provider asks for XML-signed requests.

Questions

Frequently asked questions

How do I build a SAML redirect URL?

Deflate the AuthnRequest XML with raw DEFLATE, Base64-encode it, URL-encode it and add it as SAMLRequest to the identity provider’s SSO URL. Add RelayState, and SigAlg and Signature if the request must be signed.

What is RelayState in SAML?

An opaque value the app sends with its request and gets back unchanged with the response. Apps use it to remember the page the user wanted before sign-in.

How long can RelayState be?

The SAML bindings specification limits it to 80 bytes. Send a short key and keep the real value on the app’s side.

How is a SAML redirect binding request signed?

The sender signs the string SAMLRequest=…&RelayState=…&SigAlg=… made of the URL-encoded values, and adds the Base64 result as the Signature parameter. The XML itself is not signed.

Can a SAML response use the redirect binding?

Not for browser sign-in. The Web Browser SSO profile does not allow it for responses, which are usually too large for a URL. Logout responses can use it.

Why does Keycloak refuse my hand-built SAML URL?

Usually the client requires signed requests and the URL is unsigned, or the Issuer does not match any SAML client’s client id in the realm.

What is the maximum length of a SAML redirect URL?

SAML sets none, but browsers, proxies and servers do. Typical deflated requests are a few hundred characters; larger messages should use the POST binding.

Does RelayState need to be URL-encoded?

Yes. Like every query parameter, it must be URL-encoded in the URL. The 80-byte limit applies to the value itself, before encoding.

Why is my signed redirect request rejected?

Usually the string that was signed differs from what arrived: values decoded or re-encoded, parameters in another order, or RelayState signed but not sent. Sign the exact query string you send.

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.