SAML 2.0
ulex as a SAML 2.0 identity provider: SP metadata, SP-initiated login, the Assertion Consumer Service, IdP-initiated SSO, Single Logout, signature and clock-skew validation, attribute mapping, and certificate rotation.
ulex acts as a SAML 2.0 identity provider to your applications and as a SAML 2.0 service provider to a customer's enterprise IdP. Both directions live on a saml connection.
Required scopes: read:connections for metadata and login URLs, saml:consume for ACS and SLO.
| Direction | You configure | ulex is |
|---|---|---|
| Your app federates into ulex | a saml connection pointing at your app's SP | IdP |
| ulex federates into a customer's IdP | a saml connection pointing at Okta/Entra/ADFS | SP |
#Endpoints
| Endpoint | Method | Credential | Purpose |
|---|---|---|---|
/applications/{id}/metadata | GET | none | ulex's IdP metadata, for your app to consume |
/applications/{id}/secret | GET | read:applications | the SP signing certificate, for your app to verify assertions |
/connections/{id}/saml/metadata | GET | none | the customer's IdP metadata, for ulex to consume |
/connections/{id}/saml/login | GET | none | SP-initiated; 302 to the customer IdP |
/connections/{id}/saml/acs | POST | saml:consume | ulex's ACS: where the customer IdP posts the Response |
/connections/{id}/saml/slo | GET, POST | saml:consume | single logout both ways |
/connections/{id}/saml/sso | POST | none | IdP-initiated; used by the built-in fixture IdP |
#ulex as IdP — SP metadata
curl -sS "$BASE/applications/app_01M3PSV7J8TBSPHG95CYSEX32B/metadata"<?xml version="1.0" encoding="UTF-8"?>
<EntityDescriptor xmlns="urn:oasis:names:tc:SAML:2.0:metadata" entityID="https://ulexid.com/api/v1/applications/app_01M3PSV7J8TBSPHG95CYSEX32B">
<IDPSSODescriptor WantAuthnRequestsSigned="false" protocolSupportEnumeration="urn:oasis:names:tc:SAML:2.0:protocol">
<KeyDescriptor use="signing">
<ds:KeyInfo xmlns:ds="http://www.w3.org/2000/09/xmldsig#">
<ds:X509Data>
<ds:X509Certificate>MIIDQjCCAiqgAwIBAgIGATz/FuLiMA0GCSqGSIb3DQEBBQUAMGIxCzAJBgNVBAMMAmVyb2xf…</ds:X509Certificate>
</ds:X509Data>
</ds:KeyInfo>
</KeyDescriptor>
<NameIDFormat>urn:oasis:names:tc:SAML:2.0:nameid-format:persistent</NameIDFormat>
<SingleSignOnService Binding="urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Redirect" Location="https://ulexid.com/api/v1/auth/app_01M3PSV7J8TBSPHG95CYSEX32B/sso"/>
<SingleSignOnService Binding="urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST" Location="https://ulexid.com/api/v1/auth/app_01M3PSV7J8TBSPHG95CYSEX32B/sso"/>
<SingleLogoutService Binding="urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Redirect" Location="https://ulexid.com/api/v1/auth/app_01M3PSV7J8TBSPHG95CYSEX32B/slo"/>
<AttributeConsumingService index="1">
<ServiceName xml:lang="en">Acme Support</ServiceName>
<ServiceDescription xml:lang="en">ulex SAML service provider</ServiceDescription>
<RequestedAttribute Name="email" NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:basic" isRequired="1"/>
<RequestedAttribute Name="firstName" isRequired="0"/>
<RequestedAttribute Name="lastName" isRequired="0"/>
<RequestedAttribute Name="displayName" isRequired="0"/>
<RequestedAttribute Name="title" isRequired="0"/>
<RequestedAttribute Name="department" isRequired="0"/>
<RequestedAttribute Name="groups" isRequired="0"/>
</AttributeConsumingService>
</IDPSSODescriptor>
</EntityDescriptor>Entity id, SSO URL, and SLO URL for a given application:
| Property | Value |
|---|---|
entityID | https://ulexid.com/api/v1/applications/{applicationId} |
| SSO URL (Redirect) | https://ulexid.com/api/v1/auth/{applicationId}/sso |
| SSO URL (POST) | same |
| SLO URL | https://ulexid.com/api/v1/auth/{applicationId}/slo |
Use the metadata document, not a hand-typed entity id. Hand-typed entity ids fail on the trailing character often enough to be worth avoiding entirely.
Assertion signing certificate:
curl -sS "$BASE/applications/app_01M3PSV7J8TBSPHG95CYSEX32B/secret" -H "Authorization: Bearer $ULEX_API_KEY"{
"client_id": "client_01M3PSV7J8TBSPHG95CYSEX32B",
"saml_signing_certificate": "-----BEGIN CERTIFICATE-----\nMIIDQjCCAiqgAwIBAgIGATz/FuLiMA0GCSqGSIb3D…\n-----END CERTIFICATE-----",
"saml_signing_certificate_expires_at": "2027-03-11T00:00:00.000Z",
"saml_signing_kid": "key_01M3PSVJA0YP2WDPM2RDR15MGH"
}#ulex as IdP — SP-initiated login into your app
curl -sS -L "$BASE/auth/app_01M3PSV7J8TBSPHG95CYSEX32B/sso?RelayState=st_9Kq2WmB7yLt4NxZ&login_hint=dana%40acme.example"The response is a signed <samlp:Response> on the HTTP-POST binding, posted to your app's ACS:
<samlp:Response xmlns:samlp="urn:oasis:names:tc:SAML:2.0:protocol"
xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion"
ID="_8JmQ1vZ0Xh4n7cW2sT5yP9rB3kD6fG1aH0mN"
Version="2.0" IssueInstant="2026-09-29T14:45:12Z"
Destination="https://app.example.com/saml/acs"
InResponseTo="_4Kq9WmB2yLt7NxZ1pRc6HdE0sJg3AuV8">
<saml:Issuer>https://ulexid.com/api/v1/applications/app_01M3PSV7J8TBSPHG95CYSEX32B</saml:Issuer>
<samlp:Status><samlp:StatusCode Value="urn:oasis:names:tc:SAML:2.0:status:Success"/></samlp:Status>
<saml:Assertion ID="_aH0mNqU4wE7iO2pL5xC8vB1nMg0jKhR3t"
Version="2.0" IssueInstant="2026-09-29T14:45:12Z">
<saml:Issuer>https://ulexid.com/api/v1/applications/app_01M3PSV7J8TBSPHG95CYSEX32B</saml:Issuer>
<saml:Subject>
<saml:NameID Format="urn:oasis:names:tc:SAML:2.0:nameid-format:persistent">usr_01M3PSV9GRT8GQGEG686AR1W9S</saml:NameID>
<saml:SubjectConfirmation Method="urn:oasis:names:tc:SAML:2.0:cm:bearer">
<saml:SubjectConfirmationData NotOnOrAfter="2026-09-29T14:45:17Z" Recipient="https://app.example.com/saml/acs"/>
</saml:SubjectConfirmation>
</saml:Subject>
<saml:Conditions NotBefore="2026-09-29T14:45:07Z" NotOnOrAfter="2026-09-29T14:45:17Z">
<saml:AudienceRestriction>
<saml:Audience>https://app.example.com/saml/metadata</saml:Audience>
</saml:AudienceRestriction>
</saml:Conditions>
<saml:AuthnStatement AuthnInstant="2026-09-29T14:45:12Z" SessionIndex="_s1x8Kq2WmB4yLt7">
<saml:AuthnContext>
<saml:AuthnContextClassRef>urn:ulex:acr:mfa</saml:AuthnContextClassRef>
</saml:AuthnContext>
</saml:AuthnStatement>
<saml:AttributeStatement>
<saml:Attribute Name="email"><saml:AttributeValue>dana@acme.example</saml:AttributeValue></saml:Attribute>
<saml:Attribute Name="firstName"><saml:AttributeValue>Dana</saml:AttributeValue></saml:Attribute>
<saml:Attribute Name="lastName"><saml:AttributeValue>Okafor</saml:AttributeValue></saml:Attribute>
<saml:Attribute Name="displayName"><saml:AttributeValue>Dana Okafor</saml:AttributeValue></saml:Attribute>
<saml:Attribute Name="title"><saml:AttributeValue>Support Lead</saml:AttributeValue></saml:Attribute>
<saml:Attribute Name="department"><saml:AttributeValue>Customer Success</saml:AttributeValue></saml:Attribute>
<saml:Attribute Name="groups"><saml:AttributeValue>engineering</saml:AttributeValue></saml:Attribute>
<saml:Attribute Name="org_id"><saml:AttributeValue>org_01M3PSV8HGTKQFCAYF9GDWGN3C</saml:AttributeValue></saml:Attribute>
<saml:Attribute Name="org_role"><saml:AttributeValue>owner</saml:AttributeValue></saml:Attribute>
</saml:AttributeStatement>
</saml:Assertion>
</samlp:Response>Validation rules ulex guarantees, and that your app should also enforce:
| Check | Value |
|---|---|
Destination | equals your ACS URL exactly |
InResponseTo | matches the AuthnRequest you sent |
Issuer | equals the metadata entityID |
Audience | equals your SP entity id |
NotBefore / NotOnOrAfter | 5-minute window, 120 s clock-skew tolerance |
| Assertion signature | RSA-SHA256 over the assertion, with the certificate from /secret |
NameID | persistent; the ulex usr_… id. It does not change when the user's email does |
| Replay | each Assertion/@ID is consumed once |
Configure the assertion lifetime to at least 5 minutes on your side, and make sure your clock is synchronised. ulex issues a 5-minute window; a consumer that rejects a 1-minute window will fail intermittently in a way that looks like flakiness.
#Headless SP-initiated testing
No browser needed:
{ "name": "ulex_simulate_login", "arguments": {
"application_id": "app_01M3PSV7J8TBSPHG95CYSEX32B",
"email": "dana@acme.example",
"protocol": "saml",
"return_assertion": true
} }{
"session_id": "ses_01M3PSVFC8MAB38QYAA8Q1K9MG",
"outcome": "success",
"protocol": "saml",
"in_response_to": "_4Kq9WmB2yLt7NxZ1pRc6HdE0sJg3AuV8",
"name_id": "usr_01M3PSV9GRT8GQGEG686AR1W9S",
"attributes": {
"email": "dana@acme.example",
"firstName": "Dana",
"lastName": "Okafor",
"displayName": "Dana Okafor",
"title": "Support Lead",
"department": "Customer Success",
"groups": ["engineering"]
},
"assertion_b64": "PHNhbWw6UmVzcG9uc2UgeG1sbnM6c2FtbHA6UmVzcG9uc2U…",
"not_on_or_after": "2026-09-29T14:45:17.000Z"
}Feed assertion_b64 straight into your app's ACS handler in a test. That is a real, signed, correctly-timed assertion with real attributes.
#ulex as SP — connecting to a customer's IdP
curl -sS -X POST "$BASE/connections" \
-H "Authorization: Bearer $ULEX_API_KEY" -H "Content-Type: application/json" \
-d '{
"name": "Globex SAML",
"organization_id": "org_01M3PSVT404FMFWPN6QAMM2R4P",
"config": {
"strategy": "saml",
"saml": {
"entity_id": "https://globex.okta.com/app/exk9r2mz1hRtXQ2N5s0d7",
"sso_url": "https://globex.okta.com/app/exk9r2mz1hRtXQ2N5s0d7/sso/saml",
"slo_url": "https://globex.okta.com/app/exk9r2mz1hRtXQ2N5s0d7/slo/saml",
"x509_certificate": "MIIE1DCCA3CgAwIBAgIULSJ…",
"name_id_format": "urn:oasis:names:tc:SAML:2.0:nameid-format:persistent",
"binding": "saml_redirect",
"want_response_signed": true,
"want_assertion_signed": true,
"want_authn_request_signed": false,
"signature_algorithm": "rsa-sha256",
"signature_validation": "strict",
"allowed_clock_skew_seconds": 120,
"name_id_transformations": "email",
"allow_create": true,
"allow_update": true,
"allow_link": true,
"group_attribute": "groups",
"groups_attribute": "groups",
"active_attribute": "active",
"active_value": "true",
"attribute_mapping": {
"email": "email",
"first_name": "firstName",
"last_name": "lastName",
"display_name": "displayName",
"job_title": "title",
"department": "department",
"external_id": "userId",
"groups": "groups"
}
}
}
}'{
"id": "con_01M3PSVY108K5TEHHQ82WN30YK",
"object": "connection",
"name": "Globex SAML",
"state": "draft",
"config": { "strategy": "saml", "saml": { "entity_id": "https://globex.okta.com/app/exk9r2mz1hRtXQ2N5s0d7", "binding": "saml_redirect", "signature_validation": "strict", "allowed_clock_skew_seconds": 120 } },
"last_auth_at": null,
"last_auth_result": null
}Validate before activating:
curl -sS -X POST "$BASE/connections/con_01M3PSVY108K5TEHHQ82WN30YK/verify" -H "Authorization: Bearer $ULEX_API_KEY"{
"connection_id": "con_01M3PSVY108K5TEHHQ82WN30YK",
"valid": true,
"checks": [
{ "check": "entity_id present", "status": "passed", "detail": "https://acme.okta.com/app/exkxxxx/sso/saml/metadata" },
{ "check": "sso_url present", "status": "passed", "detail": "https://acme.okta.com/app/exkxxxx/sso/saml" },
{ "check": "certificate parses", "status": "passed", "detail": "pinned certificate yields a usable public key" },
{ "check": "signature algorithm", "status": "passed", "detail": "rsa-sha256 — ulex verifies the algorithm the IdP names, it does not choose it" },
{ "check": "clock skew budget", "status": "passed", "detail": "120s" },
{ "check": "sso_url reachable", "status": "passed", "detail": "HTTP 200" }
]
}certificate parses is the one worth reading. ulex asks whether the pinned value actually yields a public key, because a field that is present is not the same as a field that is usable — a certificate the verifier cannot read passes an emptiness check and then fails every single sign-in, with nothing in ulex's logs to explain it.
Always 200, even when a check fails: read valid and checks[].
curl -sS -X POST "$BASE/connections/con_01M3PSVY108K5TEHHQ82WN30YK/activate" -H "Authorization: Bearer $ULEX_API_KEY"#Attribute mapping that actually works
| Problem | Symptom | Fix |
|---|---|---|
email is preferred_username (Entra) | 400 access_denied, user not found | attribute_mapping.email = "preferred_username" |
NameID is an opaque id | cannot link to an existing user | name_id_transformations: "email" requires the IdP to release an email attribute; otherwise "saml_subject_hash" and set allow_link: true |
| Groups are object ids | groups claim is full of GUIDs | map through a lookup table in your app, or set group_name_template and let ulex slug them |
active is "false" string, not boolean | deactivated users can still log in | active_value: "false", active_attribute: "active" — ulex compares as a string |
| Assertion is not signed | saml_signature_invalid | want_assertion_signed: true on the IdP app |
| Clock skew | saml_clock_skew | fix the IdP's NTP; only then raise allowed_clock_skew_seconds, max 600 |
#ACS and SLO
curl -sS -X POST "$BASE/connections/con_01M3PSVY108K5TEHHQ82WN30YK/saml/acs" \
-H "Content-Type: application/x-www-form-urlencoded" \
--data-urlencode "SAMLResponse=$(cat response.b64)" \
--data-urlencode "RelayState=st_9Kq2WmB7yLt4NxZ"{
"session_id": "ses_01M3PSW6T8FT4M24DH9P8YAY32",
"user_id": "usr_01M3PSWCNRG3H18C3A2AHBRYRZ",
"organization_id": "org_01M3PSVT404FMFWPN6QAMM2R4P",
"outcome": "success",
"strategy": "saml",
"amr": ["saml"],
"relay_state": "st_9Kq2WmB7yLt4NxZ",
"acs_redirect": "https://app.example.com/auth/callback?code=ac_4Kq9WmB2yLt7NxZ1pRc6HdE0sJg3AuV8&state=st_9Kq2WmB7yLt4NxZ"
}Every ACS post performs, in order:
- XML parse with external entities and DTDs disabled;
Destinationequals the connection's ACS URL and is inacs_allowed_urls;InResponseTomatches an outstanding AuthnRequest, unless the request was IdP-initiated;Issuerequalsconfig.saml.entity_id;- signature verifies against
config.saml.x509_certificate, withsignature_algorithmanddigest_algorithmenforced; Conditionstime window againstallowed_clock_skew_seconds;NameIDtransforms to a user vianame_id_transformations, honouringallow_link,allow_create,allow_update;- attributes map through
attribute_mapping; groups sync throughgroup_attribute; Assertion/@IDis recorded for replay detection;- a session is created and
InResponseTois marked consumed.
curl -sS "$BASE/connections/con_01M3PSVY108K5TEHHQ82WN30YK/saml/slo" \
-H "Authorization: Bearer $ULEX_API_KEY" \
-H "Content-Type: application/x-www-form-urlencoded" \
--data-urlencode "SAMLRequest=$(cat logout_request.b64)"SLO terminates the ulex session, revokes the refresh-token family, and returns a signed LogoutResponse. IdP-initiated logout is POST /saml/slo from the IdP with a LogoutRequest.
#IdP-initiated SSO
curl -sS -X POST "$BASE/connections/con_01M3PSVY108K5TEHHQ82WN30YK/saml/sso" \
-H "Content-Type: application/x-www-form-urlencoded" \
--data-urlencode "SAMLResponse=$(cat assertion.b64)"IdP-initiated responses have no InResponseTo. ulex accepts them only when the connection's IdP is trusted and RelayState is either absent or resolves to a registered redirect. It returns a session and an acs_redirect your app can follow, or nothing at all — IdP-initiated login cannot be replayed into a different application.
#Certificate rotation
Customer IdPs rotate certificates roughly yearly, and Entra does it without warning.
- Download the new certificate from the IdP. ulex does not parse certificate expiry dates, so there is no check that warns you in advance — the certificate is only ever used as a public key, and a key does not expire.
PATCH /connections/{id}with the newconfig.saml.x509_certificate. The connection drops tostate: "draft".POST /connections/{id}/verify→ confirmvalid: trueand thatcertificate parsespassed.POST /connections/{id}/activate.GET /audit-events?action=connection.updated&connection_id={id}to confirm.
The connection is unusable between steps 2 and 4. Schedule this in a maintenance window.
#Errors
code | Status | Cause → fix |
|---|---|---|
saml_request_invalid | 400 | malformed AuthnRequest, or a SAMLRequest that is not correctly deflated and base64-encoded |
saml_response_invalid | 400 | malformed Response, or Destination mismatch |
saml_signature_invalid | 400 | signature does not verify → re-upload the certificate, then verify |
saml_nameid_mismatch | 400 | NameID resolves to nothing and allow_link: false → set allow_link: true or name_id_transformations: "email" |
saml_acs_mismatch | 400 | InResponseTo unknown, or the ACS URL is not in acs_allowed_urls |
saml_replay_detected | 400 | this assertion id was already consumed. The IdP retried; the first one succeeded |
saml_clock_skew | 400 | outside allowed_clock_skew_seconds → fix NTP, or raise the tolerance to at most 600 |
invalid_state_transition | 409 | activate with an expired certificate or unverified domains |
connection_not_active | 403 | forgot POST /connections/{id}/activate |
#MCP equivalents
ulex_get_saml_sp_metadata, ulex_get_saml_idp_metadata, ulex_get_saml_login_url, ulex_create_connection, ulex_activate_connection, ulex_verify_connection.
Deeper: SAML SP integration, SAML metadata reference, SAML troubleshooting.