Authentication
How ulex authenticates callers and subjects: API key format and storage, OAuth 2.1 with mandatory PKCE, the hosted UI, SAML, device flow, token exchange, and the six rules that keep credentials out of logs.
ulex has two authentication problems, and conflating them is the most common integration mistake.
| Problem | Who | Credential |
|---|---|---|
| Acting on the tenant | your agent, your CI, your service | API key (ulex_sk_…) |
| Acting as a human | your application's end user | access token, minted from an OIDC or SAML login |
An API key cannot call /oauth2/userinfo. An access token cannot call POST /applications. Pick the right one for the call.
#API keys
#Format
ulex_sk_live_<32 chars> hosted tenant API key (recommended)
ulex_sk_test_<32 chars> sandbox/test prefix
ulex_sk_<32 chars> generic prefixExample: ulex_sk_live_7Qm2KpLx9Tb4Ns8RfWy3Zc1Hjf6Ee0Au
#Storage
| Part | Stored | How |
|---|---|---|
The first 14 characters (prefix) | in cleartext | for lookup |
| The remaining characters | never | scrypt, per-tenant salt, N=2^17 |
| The whole key | never | not in the database, not in a log, not in the audit event |
Returned exactly once, at creation:
{
"api_key": {
"id": "key_01M3PSVJA0YP2WDPM2RDR15MGH",
"object": "api_key",
"name": "agent-bootstrap",
"prefix": "ulex_sk_live_7Qm2K",
"scope": ["mcp:tools", "read:organizations", "write:organizations"],
"expires_at": "2026-12-28T09:00:00.000Z"
},
"key": "ulex_sk_live_7Qm2KpLx9Tb4Ns8RfWy3Zc1Hjf6Ee0Au",
"warning": "This is the only time the key is returned. Store it now."
}scrypt with N=2^17 and a per-tenant salt: about 80 ms per verification on a Lambda, which is fast enough to do on every request and slow enough to make an offline attack on a leaked hash expensive.
#Never pass a secret as a tool argument
{ "name": "ulex_create_connection", "arguments": {
"config": { "strategy": "okta_oidc", "oidc": { "client_secret": "env:ULEX_TEST_OKTA_SECRET" } }
} }An argument is written to the audit log, to your transcript, to your vendor's request log, and to whatever is replaying that transcript next week. ulex accepts env:VAR_NAME for every secret-shaped field and reads the value from its own environment at request time, storing only the ciphertext.
Fields that accept env::
| Connection | Field |
|---|---|
oidc | client_secret |
saml | — (the certificate is public) |
scim | token |
jwt | jwks |
password.ldap | bind_password |
password.radius | shared_secret |
directory | scim_token, oauth.client_secret |
#Rules
- One key per workload. A laptop and a CI job never share one.
expires_in_daysof 90 or less, always. A key with no expiry is a key you forget.- Scope narrowly.
mcp:toolsplus theread:*scopes you need covers most agent work. ip_allowlistwhen the caller has fixed egress. CIDR, up to 50 entries.ulex:adminonly in CI, from a protected runner, withip_allowlistset.- Revoke on suspicion. There is no cost to rotation; mint a new key, deploy, revoke the old one.
const key = process.env.ULEX_API_KEY;
if (!key) throw new Error("ULEX_API_KEY is not set");
// Not this, ever.
const key = "ulex_sk_live_7Qm2KpLx9Tb4Ns8RfWy3Zc1Hjf6Ee0Au";Revocation is immediate and total: the next call returns 401 api_key_revoked. There is no grace period, because a leaked key must be dead on the next request.
#OAuth 2.1
ulex is an OAuth 2.1 authorization server. What that removes matters:
| Removed | Consequence for you |
|---|---|
| The implicit grant | response_type=token is not implemented. response_type=id_token is rejected by default on https://ulexid.com unless allow_mocks: true (enabled by default in local in-memory mode) |
| The resource owner password credentials grant | no password in a token request. Ever |
response_mode=fragment for the code flow | the default is form_post, which keeps the code out of browser history |
#PKCE is mandatory
require_pkce: true and pkce_methods: ["S256"] on every new application. There is no configuration that turns it off.
code_verifier = 43–128 characters from the unreserved set
code_challenge = BASE64URL(SHA256(ASCII(code_verifier)))RFC 7636 Appendix B test vector, which the simulator honours verbatim for mock_sso:
code_verifier = dBjftJeZ4CVP-mB92K27uhbUJU1p1r_wW1gFWFOEjXk
code_challenge = E9MelhoQ2YvW96fl8sW7aTtZbGd0mY6Xl0e8Q1sCkulex_simulate_login uses that vector by default so an agent never has to get base64url-SHA256 right on the first attempt. Pass return_pkce: true for a generated pair.
#Client authentication
| Method | Use |
|---|---|
client_secret_post | the default. client_id and client_secret in the body |
client_secret_basic | HTTP Basic. URL-encode both halves before base64 |
private_key_jwt | client_assertion signed with a registered key. For a confidential client you do not want a shared secret |
none | public client. PKCE becomes the entire defence, and it is mandatory |
#Token lifetimes
| Credential | Lifetime | Rotation |
|---|---|---|
| Authorization code | 60 s | single use |
| Access token | 3,600 s | none |
| Refresh token | 2,592,000 s (30 d) | every use |
| ID token | 3,600 s | none |
| Token-exchange result | 900 s | none |
| Session | 86,400 s absolute, 604,800 s idle | re-auth every 86,400 s |
Refresh tokens rotate. Replaying a spent one revokes the whole family_id and returns invalid_grant with retryable: false. That is not a bug; it is how token theft is detected, and your app must restart the login flow rather than retry.
// Persist the new pair atomically, before the new access token is used.
await db.transaction(async (tx) => {
await tx.run("UPDATE sessions SET access_token=?, refresh_token=?, expires_at=? WHERE id=?",
[next.access_token, next.refresh_token, next.expires_at, sessionId]);
});#On a network timeout during refresh
Do not retry with the same refresh token. Introspect it first:
const state = await introspect(refreshToken);
if (state.active) return useExistingAccessToken(); // the request actually landed
// else: the family was killed. Start a new login.#Token exchange
curl -sS -X POST "$BASE/oauth2/token/exchange" \
-H "Content-Type: application/x-www-form-urlencoded" \
-d 'grant_type=urn:ietf:params:oauth:grant-type:token-exchange&
subject_token_type=urn:ietf:params:oauth:token-type:access_token&
subject_token='"$ACCESS_TOKEN"'&
audience=client_01M3PSVV38V3BJQ4SDHQPT8WMJ&
client_id=client_01M3PSV7J8TBSPHG95CYSEX32B&
client_secret='"$CLIENT_SECRET"Same sub, new sid, exp = now + 900, aud set to the downstream application. This is how you hand a user to a service without a browser.
#SAML
SAML authenticates a human. See SAML authentication and SAML SP integration.
ulex enforces, on every assertion, in this order: XML parse with DTDs and external entities disabled; Destination; InResponseTo; Issuer; signature against the connection's certificate with an enforced algorithm; the Conditions window against allowed_clock_skew_seconds; NameID resolution; attribute mapping; and Assertion/@ID replay registration.
The NameID is the ulex usr_… id and is stable across email changes. Key your local user table on it.
#The hosted UI
GET /api/v1/auth/{appId} and POST /api/v1/auth/{appId}/callback authenticate humans in a browser. They are not an API and an agent should never drive them. ulex_simulate_login runs the identical transaction server-side and returns JSON.
The session cookie is HttpOnly; Secure; SameSite=None; Domain=.ulexid.com. Only its SHA-256 is stored.
#MFA
Six factor types, four claims. See MFA and passkeys.
"amr": ["pwd", "otp", "mfa"],
"acr": "urn:ulex:acr:mfa"Branch on acr, not amr. urn:ulex:amr:simulated — the marker on a token from ulex_mint_access_token — must never satisfy an MFA check. If it does, a compromised API key is a full account takeover.
#Cross-application SSO
One session per (user, tenant), held in a cookie scoped to cookie_domain. A silent reuse is recorded as sso.session_created. See Cross-app SSO.
#What is not authentication
- A webhook signature proves ulex sent the request. It is not a way for you to call ulex.
- The
X-Ulex-Request-Idheader is a correlation label. It is not a credential and it is not verified. - A client secret inside
issuedon a deployment receipt is a credential. Store it; do not log it. - A
mcp.tool_invokedevent proves a tool ran. It does not prove the caller was authorised; theinsufficient_scopedenial is the record of that check.