OAuth 2.1 and OIDC
ulex OAuth 2.1 and OpenID Connect: discovery, the authorization endpoint, the token endpoint, PKCE, refresh rotation, introspection, revocation, JWKS, userinfo, token exchange, device flow, and the hosted sign-in endpoints.
ulex is an OAuth 2.1 authorization server and an OpenID Connect provider. Every application you register is a client.
Required scopes for the operations: openid, profile, email, offline_access for the user-facing flows; read:applications and write:applications to manage the clients themselves.
#Discovery
curl -sS https://ulexid.com/api/v1/.well-known/openid-configuration{
"issuer": "https://ulexid.com",
"authorization_endpoint": "https://ulexid.com/api/v1/oauth2/authorize",
"token_endpoint": "https://ulexid.com/api/v1/oauth2/token",
"userinfo_endpoint": "https://ulexid.com/api/v1/oauth2/userinfo",
"jwks_uri": "https://ulexid.com/api/v1/oauth2/keys",
"introspection_endpoint": "https://ulexid.com/api/v1/oauth2/introspect",
"revocation_endpoint": "https://ulexid.com/api/v1/oauth2/revoke",
"device_authorization_endpoint": "https://ulexid.com/api/v1/oauth2/authorize/device",
"token_exchange_endpoint": "https://ulexid.com/api/v1/oauth2/token/exchange",
"end_session_endpoint": "https://ulexid.com/auth/session/end",
"response_types_supported": ["code", "id_token", "code id_token"],
"response_modes_supported": ["query", "fragment", "form_post"],
"grant_types_supported": [
"authorization_code",
"refresh_token",
"client_credentials",
"urn:ietf:params:oauth:grant-type:device_code",
"urn:ietf:params:oauth:grant-type:token-exchange"
],
"subject_types_supported": ["public"],
"id_token_signing_alg_values_supported": ["RS256", "RS384", "RS512", "ES256", "ES384", "PS256", "EdDSA"],
"userinfo_signing_alg_values_supported": ["none", "RS256"],
"token_endpoint_auth_methods_supported": ["client_secret_basic", "client_secret_post", "private_key_jwt", "none"],
"token_endpoint_auth_signing_alg_values_supported": ["RS256", "PS256", "ES256"],
"scopes_supported": [
"openid", "profile", "email", "offline_access", "ulex:admin",
"read:organizations", "write:organizations", "read:users", "write:users",
"read:groups", "write:groups", "read:connections", "write:connections",
"read:directories", "write:directories", "read:applications", "write:applications",
"read:audit_logs", "read:webhooks", "write:webhooks",
"read:deployments", "write:deployments",
"mcp:tools", "mcp:admin", "scim:provision", "saml:consume", "sso:impersonate"
],
"claims_supported": [
"iss", "sub", "aud", "exp", "iat", "nbf", "jti", "azp",
"name", "given_name", "family_name", "preferred_username",
"email", "email_verified", "locale", "picture", "updated_at",
"org_id", "org_slug", "connection_id", "sid", "amr", "acr",
"https://ulexid.com/claims"
],
"code_challenge_methods_supported": ["S256", "plain"],
"dpop_signing_alg_values_supported": ["ES256", "RS256"],
"backchannel_logout_supported": true,
"backchannel_logout_session_supported": true,
"claims_parameter_supported": true,
"request_parameter_supported": true,
"require_pushed_authorization_requests": false
}curl -sS https://ulexid.com/api/v1/.well-known/oauth-authorization-serverThe same document at the RFC 8414 path. Point well-behaved clients at the first and this one is a compatibility alias.
#Authorize
GET /api/v1/oauth2/authorize
?response_type=code
&client_id=client_01M3PSV7J8TBSPHG95CYSEX32B
&redirect_uri=https%3A%2F%2Fapp.example.com%2Fauth%2Fcallback
&scope=openid%20profile%20email%20offline_access
&state=st_9Kq2WmB7yLt4NxZ
&nonce=nc_3Fq8Lp2XvN9bTm
&code_challenge=E9MelhoQ2YvW96fl8sW7aTtZbGd0mY6Xl0e8Q1sCk
&code_challenge_method=S256
&organization=org_01M3PSV8HGTKQFCAYF9GDWGN3C
&connection_id=con_01M3PSVAG0QFJG99R0M5DXSR5A
&ui_locales=en
&login_hint=dana%40acme.example| Parameter | Required | Notes |
|---|---|---|
response_type | yes | code, id_token, code id_token |
client_id | yes | |
redirect_uri | yes | must be an exact member of the application's redirect_uris |
scope | yes | must include openid for an OIDC request |
state | recommended | opaque, echoed, your CSRF defence |
nonce | required for any id_token response | binds the id_token to the session |
code_challenge + code_challenge_method | yes when require_pkce | S256 only, unless the application says otherwise |
organization | no | org id or slug; resolves the connection |
connection_id | no | forces a specific connection; must be active |
prompt | no | none, login, consent, select_account, create, mfa, step_up |
max_age | no | re-authenticate if the session is older, in seconds |
acr_values | no | demanded authentication context |
ui_locales | no | BCP-47 list, space separated |
login_hint | no | pre-fills the email on the hosted UI |
claims | no | JSON object of requested claims |
Success, with response_mode: form_post:
HTTP/2 303 See Other
location: https://app.example.com/auth/callback<form method="post" action="https://app.example.com/auth/callback">
<input type="hidden" name="code" value="ac_8Kq2WmB7yLt4NxZ1pRc6HdE0sJg3AuV8">
<input type="hidden" name="state" value="st_9Kq2WmB7yLt4NxZ">
<input type="hidden" name="iss" value="https://ulexid.com">
</form>Errors are returned as a redirect only when redirect_uri and state both validate. Otherwise they are a rendered error page, because redirecting an unvalidated URI is how open redirects happen:
HTTP/2 302 Found
location: https://app.example.com/auth/callback?error=access_denied&error_description=The+organization+only+allows+SSO+through+con_01M3PSVAG0QFJG99R0M5DXSR5A&state=st_9Kq2WmB7yLt4NxZ&iss=https%3A%2F%2Fulexid.comresponse_type=id_token and code id_token are rejected by default: implicit flow does not use PKCE correctly and is not OAuth 2.1. They are accepted only when tenant.allow_mocks is true (or in local mode) so you can reproduce a legacy client's behaviour.
#Token
curl -sS -X POST "$BASE/oauth2/token" \
-H "Content-Type: application/x-www-form-urlencoded" \
-d 'grant_type=authorization_code&
code=ac_8Kq2WmB7yLt4NxZ1pRc6HdE0sJg3AuV8&
redirect_uri=https://app.example.com/auth/callback&
client_id=client_01M3PSV7J8TBSPHG95CYSEX32B&
client_secret=cs_9fKq2WmB7yLt4NxZ1pRc6HdE0sJg3AuV8&
code_verifier=dBjftJeZ4CVP-mB92K27uhbUJU1p1r_wW1gFWFOEjXk'{
"access_token": "eyJhbGciOiJSUzI1NiIsImtpZCI6ImtleV8wMU0zUFNWSkEwWVAyV0RQTTJSRFIxNU1HSCIsInR5cCI6IkpXVCJ9…",
"token_type": "Bearer",
"expires_in": 3600,
"refresh_token": "rt_51KpXq8WvN0kTzRb7YcLd2mXe9Pf6Sg3AuV8",
"refresh_token_expires_in": 2592000,
"id_token": "eyJhbGciOiJSUzI1NiIsImtpZCI6ImtleV8wMU0zUFNWSkEwWVAyV0RQTTJSRFIxNU1HSCIsInR5cCI6IkpXVCJ9…",
"scope": "openid profile email offline_access"
}| Grant | grant_type | Needs |
|---|---|---|
| Authorization code | authorization_code | code, redirect_uri, code_verifier, client auth |
| Refresh | refresh_token | refresh_token, client auth |
| Client credentials | client_credentials | client auth, scope |
| Device code | urn:ietf:params:oauth:grant-type:device_code | device_code, client auth |
| Token exchange | urn:ietf:params:oauth:grant-type:token-exchange | subject_token, subject_token_type, audience |
The implicit grant (response_type=token) and the password grant are not implemented. OAuth 2.1 removes both.
Errors use the standard OAuth body plus the ulex envelope fields:
{
"error": "invalid_grant",
"error_description": "The authorization code has already been used.",
"error_uri": "https://docs.ulexid.com/api-reference/errors#invalid_grant",
"type": "authentication_error",
"code": "invalid_grant",
"request_id": "req_01M3PSW9R0175NAW62NYR403R8",
"retryable": false,
"hint": "Authorization codes are single use. Start a new login with ulex_simulate_login."
}#Client authentication
| Method | Header or field |
|---|---|
client_secret_post | client_id and client_secret in the body (default) |
client_secret_basic | Authorization: Basic base64(urlencode(client_id):urlencode(client_secret)) |
private_key_jwt | client_assertion_type=urn:ietf:params:oauth:client-assertion-type:jwt-bearer plus a client_assertion signed with the registered key |
none | public client; client_id in the body only. PKCE is mandatory |
#Refresh
curl -sS -X POST "$BASE/oauth2/token" \
-H "Content-Type: application/x-www-form-urlencoded" \
-d 'grant_type=refresh_token&
refresh_token=rt_51KpXq8WvN0kTzRb7YcLd2mXe9Pf6Sg3AuV8&
client_id=client_01M3PSV7J8TBSPHG95CYSEX32B&
client_secret=cs_9fKq2WmB7yLt4NxZ1pRc6HdE0sJg3AuV8'{
"access_token": "eyJhbGciOiJSUzI1NiIsImtpZCI6ImtleV8wMU0zUFNWSkEwWVAyV0RQTTJSRFIxNU1HSCIsInR5cCI6IkpXVCJ9…",
"token_type": "Bearer",
"expires_in": 3600,
"refresh_token": "rt_9Lm3Qv7Xw2NbK5Rt8Yc1HdE4sJg6Pf0Au",
"refresh_token_expires_in": 2520000,
"scope": "openid profile email offline_access"
}Refresh tokens rotate on every use. Store the new one atomically with the new access token, and never retry a refresh with a token you have already spent. A replay kills the whole family_id and every token in it becomes invalid — that is how token theft is detected, and it is not a bug.
#Client credentials
curl -sS -X POST "$BASE/oauth2/token" \
-H "Content-Type: application/x-www-form-urlencoded" \
-d 'grant_type=client_credentials&
client_id=client_01M3PSV7J8TBSPHG95CYSEX32B&
client_secret=cs_9fKq2WmB7yLt4NxZ1pRc6HdE0sJg3AuV8&
scope=read:users%20read:organizations'{
"access_token": "eyJhbGciOiJSUzI1NiIsImtpZCI6ImtleV8wMU0zUFNWSkEwWVAyV0RQTTJSRFIxNU1HSCIsInR5cCI6IkpXVCJ9…",
"token_type": "Bearer",
"expires_in": 3600,
"scope": "read:users read:organizations"
}No refresh_token, no id_token, no sub for a human. sub is the client_id. Use it for a service account reading your own directory, never for anything that acts on behalf of a user.
#Token exchange (RFC 8693)
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=eyJhbGciOiJSUzI1NiIsImtpZCI6ImtleV8wMU0zUFNWSkEwWVAyV0RQTTJSRFIxNU1HSCIsInR5cCI6IkpXVCJ9…&
audience=client_01M3PSVV38V3BJQ4SDHQPT8WMJ&
client_id=client_01M3PSV7J8TBSPHG95CYSEX32B&
client_secret=cs_9fKq2WmB7yLt4NxZ1pRc6HdE0sJg3AuV8'{
"access_token": "eyJhbGciOiJSUzI1NiIsImtpZCI6ImtleV8wMU0zUFNWSkEwVVAyV0RQTTJSRFIxNU1HSCIsInR5cCI6IkpXVCJ9…",
"issued_token_type": "urn:ietf:params:oauth:token-type:access_token",
"token_type": "Bearer",
"expires_in": 900,
"scope": "openid profile email"
}The target application must list urn:ietf:params:oauth:grant-type:token-exchange in grant_types, else 403 unauthorized_client. The new token has the same sub, a new sid, exp = now + 900, and aud set to the requested audience. This is how you hand a user to a downstream service without a browser.
#Device flow
curl -sS -X POST "$BASE/oauth2/device/code" \
-H "Content-Type: application/x-www-form-urlencoded" \
-d 'client_id=client_01M3PSV7J8TBSPHG95CYSEX32B&scope=openid%20profile'{
"device_code": "dc_7Kq2WmB4yLt4NxZ1pRc6HdE0sJg3AuV8",
"user_code": "WXYZ-1234",
"verification_uri": "https://ulexid.com/device",
"verification_uri_complete": "https://ulexid.com/device?user_code=WXYZ-1234",
"expires_in": 900,
"interval": 5
}Complete headlessly, with no browser:
{ "name": "ulex_simulate_login", "arguments": {
"application_id": "app_01M3PSV7J8TBSPHG95CYSEX32B",
"user_code": "WXYZ-1234",
"email": "dana@acme.example"
} }Then poll the token endpoint at the interval, not faster:
curl -sS -X POST "$BASE/oauth2/token" \
-H "Content-Type: application/x-www-form-urlencoded" \
-d 'grant_type=urn:ietf:params:oauth:grant-type:device_code&
device_code=dc_7Kq2WmB4yLt4NxZ1pRc6HdE0sJg3AuV8&
client_id=client_01M3PSV7J8TBSPHG95CYSEX32B'{
"error": "authorization_pending",
"error_description": "The user has not yet completed the device authorization.",
"type": "invalid_request_error",
"code": "login_required",
"request_id": "req_01M3PSW9R0175NAW62NYR403R8",
"retryable": true,
"hint": "Retry after 5s."
}authorization_pending, slow_down, access_denied, and expired_token are the four device-flow polling states. Honour interval, and increase it by 5 seconds on every slow_down.
#Userinfo
curl -sS "$BASE/oauth2/userinfo" -H "Authorization: Bearer eyJhbGciOiJSUzI1NiIsImtpZCI6ImtleV8wMU0zUFNWSkEwWVAyV0RQTTJSRFIxNU1HSCIsInR5cCI6IkpXVCJ9…"{
"sub": "usr_01M3PSV9GRT8GQGEG686AR1W9S",
"iss": "https://ulexid.com",
"aud": "client_01M3PSV7J8TBSPHG95CYSEX32B",
"name": "Dana Okafor",
"given_name": "Dana",
"family_name": "Okafor",
"preferred_username": "dana@acme.example",
"email": "dana@acme.example",
"email_verified": true,
"job_title": "Support Lead",
"department": "Customer Success",
"locale": "en-US",
"updated_at": 1790693112,
"org_id": "org_01M3PSV8HGTKQFCAYF9GDWGN3C",
"org_slug": "acme",
"connection_id": "con_01M3PSVAG0QFJG99R0M5DXSR5A",
"sid": "ses_01M3PSVFC8MAB38QYAA8Q1K9MG",
"amr": ["pwd", "otp", "mfa"],
"acr": "urn:ulex:acr:mfa",
"https://ulexid.com/claims": { "org_role": "owner", "groups": ["engineering"] }
}A refresh token at /userinfo is 401 invalid_token. Introspection is the only place a refresh token is accepted.
Full claim list and which scopes unlock which: OIDC claim reference.
#Introspection (RFC 7662)
# HTTP Basic, exactly as at the token endpoint. A tenant API key is not accepted here.
curl -sS -X POST "$BASE/oauth2/introspect" \
-H "Content-Type: application/x-www-form-urlencoded" \
-u "$CLIENT_ID:$CLIENT_SECRET" \
-d 'token=eyJhbGciOiJSUzI1NiIsImtpZCI6ImtleV8wMU0zUFNWSkEwWVAyV0RQTTJSRFIxNU1HSCIsInR5cCI6IkpXVCJ9…&token_type_hint=access_token'{
"active": true,
"token_type": "access_token",
"scope": "openid profile email offline_access",
"client_id": "client_01M3PSV7J8TBSPHG95CYSEX32B",
"sub": "usr_01M3PSV9GRT8GQGEG686AR1W9S",
"org_id": "org_01M3PSV8HGTKQFCAYF9GDWGN3C",
"sid": "ses_01M3PSVFC8MAB38QYAA8Q1K9MG",
"exp": 1790696712,
"iat": 1790693112,
"auth_time": 1790693112,
"amr": ["pwd", "otp", "mfa"],
"acr": "urn:ulex:acr:mfa"
}An unknown, expired, or revoked token returns 200 with {"active": false} — never 401. This is deliberate: introspection must not be an oracle for token validity.
The endpoint requires OAuth client authentication — HTTP Basic with the same client_id and client_secret the token endpoint uses. RFC 7662 §2.1 requires authorization on this endpoint, and an unauthenticated one is a token-validity oracle over the whole environment: the signing keys are resolved from the token's own iss, so a caller could ask whether any token was live, which client held it, and which user it named, without holding a credential for any of them. A tenant API key (ulex_sk_…) is not accepted — use a client credential, or POST /api/v1/tokens/introspect if a management path is needed.
A client authenticated under a tenant prefix may only introspect that tenant's tokens. A token from elsewhere returns {"active": false} rather than an error, and an unauthenticated or wrong-secret call is 401 invalid_client with nothing about the token in the body.
#Revocation (RFC 7009)
curl -sS -X POST "$BASE/oauth2/revoke" \
-H "Content-Type: application/x-www-form-urlencoded" \
-H "Authorization: Bearer $CLIENT_CREDENTIAL" \
-d 'token=rt_51KpXq8WvN0kTzRb7YcLd2mXe9Pf6Sg3AuV8&token_type_hint=refresh_token'{ "revoked": true, "token_type": "refresh_token", "family_revoked": true, "sessions_revoked": 0 }Revoking a refresh token revokes the entire family_id and returns family_revoked: true. Revoking an access token revokes just that token; it does not touch the session. Add "revoke_session": true as an extra form field to revoke every token issued in the same session.
Revoking an already-revoked or unknown token returns 200 with {"revoked": true} — never 400. Do not treat revocation failure as an error.
#JWKS
curl -sS "$BASE/oauth2/keys"{
"keys": [
{
"kty": "RSA",
"use": "sig",
"alg": "RS256",
"kid": "key_01M3PSVJA0YP2WDPM2RDR15MGH",
"n": "0vx7agoKGcRMgpjY4XqbJ7Xm3vJ7XQ…",
"e": "AQAB",
"x5c": ["MIIDQjCCAiqgAwIBAgIGATz/FuLiMA0GCSqGSIb3DQEBBQUAMGIxCzAJBgNVBAMMAmVyb2xf…"],
"x5t": "MfKw2WL8iJ7YQ3n1bPqR0sA=="
}
]
}Public, no credential, cacheable for up to 24 hours but re-fetch at least every 15 minutes. During a key rotation the JWKS contains two keys: the new one (state: active) and the retiring one. Keep a kid-keyed map, not a single pinned key. See Key management and zero-downtime rotation.
#Hosted sign-in
GET /api/v1/auth/{appId}?organization=acme&login_hint=dana%40acme.example&redirect_uri=…Renders the hosted UI using the application's branding, default_locale, and the organization's logo. POST /api/v1/auth/{appId}/callback is its server-side form target and performs the same transaction as /oauth2/authorize.
Neither endpoint is an API: responses are HTML, and an agent has no business driving them. ulex_simulate_login runs the identical transaction and returns JSON. Use the UI for humans, the tool for agents.
#End session
GET /api/v1/auth/session/end?id_token_hint=…&post_logout_redirect_uri=https%3A%2F%2Fapp.example.com%2Fbye&state=…Terminates the session, revokes the refresh-token family, and redirects. post_logout_redirect_uri must be in the application's cross_app_sso_redirect_urls.
#Token lifetimes
| Token | Lifetime | Rotation | On reuse |
|---|---|---|---|
| Authorization code | 60 s | single use | invalid_grant |
| Access token | 3,600 s | none | — |
| Refresh token | 2,592,000 s | every use | family revoked, invalid_grant |
| ID token | 3,600 s | none | — |
| Token exchange result | 900 s | none | — |
| Client-credentials token | 3,600 s | none | — |
#Errors
code | Status | Cause |
|---|---|---|
invalid_request | 400 | a required parameter is missing |
invalid_client | 401 | unknown client_id, or bad client authentication |
invalid_grant | 400 | code expired or reused, redirect_uri mismatch, or refresh-token reuse |
invalid_redirect_uri | 400 | not in the application's redirect_uris |
unauthorized_client | 403 | grant type not enabled, or the client may not do this |
unsupported_grant_type | 400 | implicit or password grant |
code_verifier_mismatch | 400 | PKCE failure |
invalid_scope | 400 | a scope the application or key does not hold |
access_denied | 403 | sso_only violation, suspended user, or user refused |
login_required | 401 | prompt=none and no session |
mfa_required | 401 | MFA outstanding |
rate_limit_error | 429 | 30 token requests per minute per client |
#MCP equivalents
ulex_get_authorization_url, ulex_exchange_code_for_tokens, ulex_refresh_tokens, ulex_revoke_tokens, ulex_introspect_token, ulex_get_userinfo, ulex_mint_access_token, ulex_simulate_login.
Deeper: OIDC client integration, Hosted login, Cross-app SSO, Claim reference.