Cross-app SSO
How ulex's shared session cookie gives a human one sign-in across every application in a tenant: enabling it, cookie domain and SameSite, session application_ids, the silent-renewal loop, and what happens when it is turned off.
A human with accounts in four of your applications should type their password once.
#How it works
ulex issues one session per (user, tenant), not per (user, tenant, application). The session is held in a cookie scoped to cookie_domain, which defaults to .ulexid.com and is therefore visible to every application in the tenant.
1. Human signs in at ulexid.com → session ses_… created, cookie set
2. Human visits acme-support.ulexid.com → no local session
3. acme-support redirects to /api/v1/auth/{appId}/sso
4. ulex sees the cookie, finds a live session, no prompt
5. ulex issues an authorization_code for THIS application
6. acme-support exchanges it, gets its own local session
7. Human never sees a login screen againsession.application_ids records which applications have used the session. It grows as they do, is capped at 50, and is what the audit log's sso.session_created action is derived from.
#Enabling it
Cross-app SSO is on by default. You configure it per application:
curl -sS -X PATCH "$BASE/applications/app_01M3PSV7J8TBSPHG95CYSEX32B" \
-H "Authorization: Bearer $ULEX_API_KEY" -H "Content-Type: application/json" \
-d '{
"cross_app_sso_enabled": true,
"cookie_domain": ".ulexid.com",
"cross_app_sso_redirect_urls": ["https://app.example.com/auth/callback"]
}'{
"id": "app_01M3PSV7J8TBSPHG95CYSEX32B",
"object": "application",
"cross_app_sso_enabled": true,
"cookie_domain": ".ulexid.com",
"cross_app_sso_redirect_urls": ["https://app.example.com/auth/callback"]
}| Field | Default | Notes |
|---|---|---|
cross_app_sso_enabled | true | when false, this application is never served by a session another application created. It still signs people in. |
cookie_domain | .ulexid.com | must be a suffix of every application's host |
cross_app_sso_redirect_urls | [] | the URIs the session may be handed back to; also used by end_session |
auth_policy.session.cross_app_sso | true | the tenant-wide kill switch |
cookie_domain must be a suffix of every application's host, or the cookie is not visible to it and you get no SSO, with no error. If applications live on different domains, cross-app SSO is not available to you without a shared parent domain.
#Silent renewal, and why it is dangerous
Because a session is reusable, you can refresh an access token without a prompt. That is convenient and it is a footgun.
Do not use prompt=none as a token-refresh mechanism. It turns every token refresh into an interactive round trip, and when the session has expired it returns login_required with retryable: false — your refresh handler has to distinguish "session gone, send them to login" from "not allowed", and it usually does not.
The correct shape is: refresh the refresh token, and if that fails, send the human to /api/v1/auth/{appId}/sso. They will not be prompted, because the session is still alive.
export async function ensureToken(session: Session): Promise<TokenSet> {
if (session.token.expires_at - 300 > Date.now() / 1000) return session.token;
try {
return await rotateRefreshToken(session.token.refresh_token);
} catch (err) {
if (isUlexError(err) && (err.code === "invalid_grant" || err.code === "token_revoked")) {
// The ulex session is gone or the family was killed. Send them through
// SSO; if ulex still has a session they are not prompted.
return { redirectTo: `https://ulexid.com/auth/${APP_ID}?return_to=${encodeURIComponent(RETURN_TO)}` };
}
throw err;
}
}#Sessions are per tenant, not global
A human who is a member of three customer organizations has one ulex session and one cookie, and their org_id claim is whichever organization the current authorization named.
This means:
- a session is not an authorization. Every request still has to check the org.
- signing into a second application with a different
organizationparameter does not create a second cookie; it changes what the next token says. - if you need a user to hold two orgs simultaneously in different tabs, pass
organizationon each authorization and store theorg_idfrom the resulting token, not from the session.
export function orgFromToken(claims: AccessTokenClaims): string {
if (!claims.org_id) throw new Error("token has no org_id; the authorization named no organization");
return claims.org_id;
}#Turning it off
curl -sS -X PATCH "$BASE/applications/app_01M3PSV7J8TBSPHG95CYSEX32B" \
-H "Authorization: Bearer $ULEX_API_KEY" -H "Content-Type: application/json" \
-d '{"cross_app_sso_enabled": false}'Or tenant-wide, via the auth policy:
curl -sS -X PUT "$BASE/auth-policy" -H "Authorization: Bearer $ULEX_API_KEY" -H "Content-Type: application/json" \
-d '{"session": {"cross_app_sso": false}}'Turning it off does not revoke existing sessions. It only stops new authorizations from reusing them silently. To end every session now, revoke them.
#What gets audited
| Action | When |
|---|---|
authentication.session_created | a new session, whether from a prompt or a silent reuse |
sso.session_created | specifically, a session created by cross-app reuse with no prompt |
authentication.session_revoked | logout, suspend, deprovision, or secret rotation |
authentication.session_expired | past idle_expires_at (7 days) or expires_at (24 h) |
{
"id": "aud_01M3PSW3WGDDFJFJHZ4QJNNFZD",
"action": "sso.session_created",
"category": "authentication",
"actor_type": "user",
"target": { "type": "application", "id": "app_01M3PSVV38V3BJQ4SDHQPT8WMJ", "display_name": "Acme Analytics" },
"organization_id": "org_01M3PSV8HGTKQFCAYF9GDWGN3C",
"session_id": "ses_01M3PSVFC8MAB38QYAA8Q1K9MG",
"metadata": { "silent": true, "new_application": true, "session_age_seconds": 184 },
"outcome": "success",
"timestamp": 1790693112
}metadata.new_application: true marks the first time a given application used this session — that is the "user has now onboarded to N of your apps" metric.
#Testing it
it("does not prompt a user who already has a session", async () => {
// First application.
const first = await tools.ulex_simulate_login({
application_id: "app_01M3PSV7J8TBSPHG95CYSEX32B",
organization_id: "org_01M3PSV8HGTKQFCAYF9GDWGN3C",
email: "dana@acme.example",
});
expect(first.outcome).toBe("success");
expect(first.prompted).toBe(false);
// Second application, same session.
const second = await tools.ulex_simulate_login({
application_id: "app_01M3PSVV38V3BJQ4SDHQPT8WMJ",
organization_id: "org_01M3PSV8HGTKQFCAYF9GDWGN3C",
email: "dana@acme.example",
});
expect(second.session_id).toBe(first.session_id); // the same ulex session
expect(second.prompted).toBe(false);
// And the audit log records it as a silent SSO, not a new authentication.
const events = await tools.ulex_search_audit_logs({ action: "sso.session_created", limit: 10 });
expect(events.data.some((e) => e.target?.id === "app_01M3PSVV38V3BJQ4SDHQPT8WMJ")).toBe(true);
});#Security notes
- The cookie is
HttpOnly,Secure,SameSite=Nonewhere cross-site SSO requires it, andPath=/. There is noDomainbeyondcookie_domain. - A session reused silently is still bound to the
user_agentrecorded when it was created.auth_policy.session.bind_to_user_agentdefaults totrue, and a mismatch revokes the session rather than merely refusing the request. auth_policy.session.bind_to_ipisfalseby default. Turn it on for high-assurance tenants and accept that mobile users will be prompted when they change networks. The comparison is against a pseudonym of the address; the raw address is never stored on the session or in the audit log.- Reauthentication is required every 24 hours by default (
session.reauthenticate_after_seconds), even for a live session. session.device_fingerprintis a schema field with no implementation: it is written asnullat creation and never populated or compared. Binding is on user agent and (optionally) address. Treat the field as reserved.