Guides

MFA and passkeys

ulex strong authentication: MFA factors, TOTP, WebAuthn passkeys with clone detection, adaptive MFA policies, the amr and acr claims, headless MFA simulation for agents, and what is never stored.

#What ulex stores

Factor typeStoredNever stored
totpthe shared secret, encrypted with the tenant KEK—
smsSHA-256 of the phone number, in target_hintthe phone number
emailSHA-256 of the addressthe address
webauthnthe credential id and public keyany private key, ever, anywhere
pushthe device registration—
backup_codeSHA-256 of each code, one-timethe codes

secret_encrypted is never serialised to any client. target_hint is a salted SHA-256, so an operator reading the database cannot reconstruct a phone number.

#Passkeys

json
{
  "id": "psk_01M3PSVR5GYASQ2ETPYPC11Y2A",
  "object": "passkey",
  "user_id": "usr_01M3PSV9GRT8GQGEG686AR1W9S",
  "credential_id": "8JmQ1vZ0Xh4n7cW2sT5yP9rB3kD6fG1aH0mN",
  "counter": 0,
  "transports": ["internal", "hybrid"],
  "aaguid": "adce0002-35bc-c60a-648b-0b25f1f05503",
  "device_type": "multi_device",
  "backed_up": true,
  "name": "MacBook Pro",
  "created_at": "2026-09-29T14:42:22.000Z",
  "last_used_at": "2026-09-29T14:45:12.000Z"
}
FieldWhy it exists
counterWebAuthn signature counter. A counter that does not increase indicates a cloned authenticator and ulex rejects the assertion. This is the single most important passkey field.
aaguididentifies the authenticator model. A new aaguid on an existing credential_id is suspicious
backed_uptrue when the credential is synced through a platform passkey manager. A behaviour signal for risk, not a rejection
device_typesingle_device credentials do not sync; multi_device do
transportsusb, nfc, ble, internal, hybrid

When ulex rejects a cloned passkey it writes authentication.mfa_failed with error_code: "passkey_counter_regression" and suspends the credential pending re-enrolment.

#The auth policy

json
{
  "mfa": {
    "mode": "adaptive",
    "methods": ["webauthn", "totp", "push"],
    "remember_device_days": 30,
    "trigger_on_new_device": true,
    "trigger_on_ip_change": true,
    "trigger_on_high_risk": true
  },
  "password": {
    "min_length": 12,
    "require_uppercase": true,
    "require_lowercase": true,
    "require_number": true,
    "require_symbol": true,
    "check_breached_passwords": true,
    "max_age_days": 365,
    "forbid_reuse_count": 5
  },
  "session": {
    "lifetime_seconds": 86400,
    "idle_timeout_seconds": 604800,
    "reauthenticate_after_seconds": 86400,
    "bind_to_ip": false,
    "bind_to_user_agent": true,
    "cross_app_sso": true
  }
}

#mfa.mode

ModeBehaviour
optionalchallenges users who enrolled a usable TOTP or recovery factor; users without one are not challenged
requiredchallenges users who enrolled a usable TOTP or recovery factor; users without one can still sign in
adaptivestored but NOT applied; there is no risk engine

required does not currently require enrollment. ulex has no first-factor enrollment ceremony, so enforcing that for existing users would lock them out with no recovery path. Do not represent this mode as universal MFA enforcement. methods, remember_device_days, and trigger_on_* are also stored but NOT applied.

#password.check_breached_passwords

Compares against a k-anonymity breach corpus: the first five characters of the SHA-1 hash go out, the corpus returns candidates, the comparison happens locally. The password itself never leaves the process. NIST SP 800-63B guidance.

The tenant's check_breached_passwords value controls screening. ULEX_SCREEN_PASSWORDS is the deployment-wide default only when no tenant auth policy exists; a tenant setting overrides it. A match is a warning, not a password refusal.

#The amr and acr claims

amr (authentication methods reference) tells you how the user authenticated:

json
"amr": ["pwd", "otp", "mfa"],
"amr_details": [
  { "method": "pwd", "acr": "urn:ulex:acr:pwd" },
  { "method": "otp", "acr": "urn:ulex:acr:otp" },
  { "method": "webauthn", "acr": "urn:ulex:acr:mfa", "ts": 1790693112 }
]
amr valueMeans
pwdpassword
otpone-time code, TOTP or email
smsSMS
webauthnpasskey
pushedpush notification
mfaa second factor was satisfied, in addition to the above
samlfederated through SAML
oidcfederated through upstream OIDC
hwkhardware key
urn:ulex:amr:simulatedulex_mint_access_token; not a real authentication

acr (authentication context class reference) tells you how strong it was:

acrMeaning
urn:ulex:acr:pwdpassword only
urn:ulex:acr:otppassword plus one-time code
urn:ulex:acr:mfapassword plus a second factor
urn:ulex:acr:phishing-resistantpasskey or hardware key
urn:ulex:acr:simulatedforged by the simulator

Your application should branch on acr, not on amr. amr tells you the history; acr tells you whether it was good enough.

ts
export function isPhishingResistant(claims: AccessTokenClaims): boolean {
  return claims.acr === "urn:ulex:acr:phishing-resistant" || claims.amr?.includes("webauthn") === true;
}

export function requireMfa(claims: AccessTokenClaims): void {
  if (claims.acr !== "urn:ulex:acr:mfa" && claims.acr !== "urn:ulex:acr:phishing-resistant") {
    throw new Error("this action requires MFA");
  }
}

#Demanding a level

http
GET /api/v1/oauth2/authorize?...&acr_values=urn:ulex:acr:mfa&max_age=0

If the current session does not meet the demand, the response is 401 step_up_required (not 403), retryable: false, with hint: "Re-authenticate with acr_values=urn:ulex:acr:mfa."

max_age=0 forces reauthentication regardless of session age. Combine it with acr_values for sensitive operations.

#Simulating MFA as an agent

You never touch an authenticator app. Three calls.

json
{ "name": "ulex_simulate_mfa", "arguments": { "mode": "challenge", "email": "dana@acme.example", "method": "webauthn" } }
json
{
  "challenge_id": "mfa_01M3PSVS4RVKHQVRPCKNJGYBEZ",
  "armed": true,
  "methods": ["totp", "webauthn", "push"],
  "method": "webauthn",
  "expires_at": "2026-09-29T14:55:12.000Z",
  "code": "418902"
}

Now attempt the login. It will be challenged, not completed:

json
{ "name": "ulex_simulate_login", "arguments": { "application_id": "app_01M3PSV7J8TBSPHG95CYSEX32B", "email": "dana@acme.example" } }
json
{
  "session_id": null,
  "grant_id": null,
  "outcome": "challenge",
  "stage": "mfa",
  "error": {
    "type": "authentication_error",
    "code": "mfa_required",
    "message": "A second factor is required before this authorization can complete.",
    "request_id": "req_01M3PSX7B2KQ4V6W8Y0Z1A3B5C",
    "retryable": false,
    "hint": "Present the challenge to the user, or satisfy it with ulex_simulate_mfa { mode: 'satisfy' }."
  },
  "amr": ["pwd"],
  "acr": null
}

Satisfy it and log in again:

json
{ "name": "ulex_simulate_mfa", "arguments": { "mode": "satisfy", "challenge_id": "mfa_01M3PSVS4RVKHQVRPCKNJGYBEZ" } }
json
{ "satisfied": true, "amr": ["pwd", "otp", "mfa"] }
json
{ "name": "ulex_simulate_login", "arguments": { "application_id": "app_01M3PSV7J8TBSPHG95CYSEX32B", "email": "dana@acme.example" } }
json
{
  "session_id": "ses_01M3PSVFC8MAB38QYAA8Q1K9MG",
  "grant_id": "grt_01M3PSVGBGJT1ZXC840F2B3NXJ",
  "outcome": "success",
  "stage": "complete",
  "amr": ["pwd", "otp", "mfa"],
  "acr": "urn:ulex:acr:mfa",
  "code": "ac_8Kq2WmB7yLt4NxZ1pRc6HdE0sJg3AuV8",
  "code_expires_at": "2026-09-29T14:46:12.000Z"
}

The resulting token's amr contains mfa and acr is urn:ulex:acr:mfa. That is the assertion you want to make in a test.

#Testing the failure path

json
{ "name": "ulex_simulate_mfa", "arguments": { "mode": "challenge", "email": "dana@acme.example", "method": "totp" } }
json
{ "name": "ulex_simulate_mfa", "arguments": { "mode": "fail", "challenge_id": "mfa_01M3PSVS4RVKHQVRPCKNJGYBEZ" } }
json
{
  "satisfied": false,
  "outcome": "failure",
  "error": { "type": "authentication_error", "code": "invalid_otp", "message": "That code is not correct.", "retryable": false },
  "audit_action": "authentication.mfa_failed",
  "attempts_remaining": 2
}

attempts_remaining: 2 matters: ulex locks the challenge after 3 failures, and after 5 locked challenges it requires a fresh login_hint rather than a silent retry. Implement the lockout in your client or you will hammer a challenge that is already dead.

#Enrolling a user with MFA

mock_sso connections can seed enrollment:

json
{
  "name": "ulex_create_connection",
  "arguments": {
    "name": "Acme SSO",
    "config": {
      "strategy": "mock_sso",
      "mock": {
        "seed_users": [
          { "email": "dana@acme.example", "first_name": "Dana", "mfa_enrolled": true, "status": "active" },
          { "email": "pat@acme.example", "first_name": "Pat", "mfa_enrolled": false, "status": "active" }
        ]
      }
    }
  }
}

mfa_enrolled: true means the user is challenged. false means they are not, unless the policy is required or adaptive with no factor enrolled.

bash
curl -sS "$BASE/users/usr_01M3PSV9GRT8GQGEG686AR1W9S/mfa-factors" -H "Authorization: Bearer $ULEX_API_KEY" | jq
curl -sS "$BASE/users/usr_01M3PSV9GRT8GQGEG686AR1W9S/passkeys" -H "Authorization: Bearer $ULEX_API_KEY" | jq

#What is audited

ActionWhen
authentication.challengeany step-up or MFA challenge was raised
authentication.mfa_challengean MFA prompt was presented
authentication.mfa_faileda wrong or missing code, or a passkey counter regression
authentication.succeededcarries metadata.amr and metadata.acr
bash
curl -sS -G "$BASE/audit-events" -H "Authorization: Bearer $ULEX_API_KEY" \
  --data-urlencode 'action_prefix=authentication.' \
  --data-urlencode 'since=2026-09-29T00:00:00.000Z' | jq '.data[] | {action, outcome, error_code, amr: .metadata.amr}'

#Checklist before you go live

  • [ ] acr_values is checked in your application, not just amr.
  • [ ] urn:ulex:acr:phishing-resistant is required for the highest-risk operations, not urn:ulex:acr:mfa.
  • [ ] A failed MFA attempt does not retry automatically.
  • [ ] The lockout counter is respected.
  • [ ] Passkey counter regression is handled as credential compromise, not as a bug.
  • [ ] check_breached_passwords is on for any tenant using password or ldap.
  • [ ] A recovery path exists that does not let an agent bypass MFA. ulex_mint_access_token writes no authentication event and its amr is urn:ulex:amr:simulated; if your app accepts that claim, a compromised API key becomes a full account takeover.

#Reference