Skip to content
Talk to our solutions team

Magic link, WebAuthn and passkeys

iam.svc ships two passwordless code paths. Magic link works end to end: two public routes, a one-time code delivered through notify.svc, and the same login response password login returns. WebAuthn and passkeys run once a relying party is set: a webauthn: block on the tenant’s node, or on iam’s cluster node for every tenant that sets none. Without one, the four routes answer 503 webauthn_disabled.

Both flows are realm-aware. A realm offers magic link by listing a provider declared type: magic, and WebAuthn by listing one declared type: webauthn. The person is found in the chosen realm’s entity and the token carries that realm, see Realms and providers.

MethodPathAuthRate-limit profile
POST/auth/magic/requestpublicauth_magic
POST/auth/magic/verifythe code is the credentialauth_magic

Both routes require the four CEPT headers (X-Customer, X-Product, X-Env, X-Tenant). The auth_magic bucket is 15 requests capacity refilling at 0.25 per second, keyed per (tenant, caller IP), in memory and per instance.

POST /auth/magic/request
Content-Type: application/json
X-Customer: acme
X-Product: iam
X-Env: prod
X-Tenant: main
{ "email": "[email protected]" }
{ "ok": true }

The response is 200 {"ok": true} for a registered email, an unregistered email, and a malformed body alike. Nothing in the response distinguishes them, and no code is generated for an address that matches nobody in the realm’s entity.

On a match the service:

  1. Generates 32 random bytes, base64url-encoded: the plaintext code.
  2. Writes a user_magic_link row holding hex(SHA-256(code)) in token, provider "email", approved false, and expiresat = now + 15 minutes.
  3. Hands the plaintext to the notification sink with purpose magic_link and channel email.
  4. Emits after_magic_request carrying sent and, on delivery failure, sink_error.

The order of checks is worth knowing when you test the endpoint: a body that is not valid JSON, or one with an empty email, returns 200 {"ok": true} before the tenant is resolved, a well-formed body with no CEPT headers returns 400 no_tenant.

before_magic_request fires after the tenant check and before the user lookup, and can abort the request. An abort is not visible to the caller. The endpoint still answers 200 {"ok": true}. Internal failures are the only thing that breaks the uniform 200: 500 engine_unavailable, 500 code_failed and 500 persist_failed are all reachable once the tenant resolves.

Delivery is a service-level concern, not a per-product one. The sink is wired from the notify.url service config key:

notify.urlBehaviour
setPOST {notify.url}/notify/email/sync, carrying the four CEPT headers and a per-tenant service token minted from that tenant’s own signing key; upgraded to mTLS when a managed TLS config is registered for the service
unsetCodes are generated, hashed and persisted; nothing is delivered; the endpoint still returns 200

The outbound body:

{
"tenantkey": "acme:prod:iam:main",
"templatename": "magic_link",
"data": {
"code": "<plaintext code>",
"user_id": "U01K…",
"user_email": "[email protected]",
"user_firstname": "…",
"user_lastname": "…",
"user_displayname": "…",
"expires_in_minutes": 15
},
"provider_context": { "to": "[email protected]", "user_id": "U01K…" },
"idempotency_key": "01J…"
}

templatename is always the literal magic_link, the template: field on a magic-type provider declaration in providers.yaml is parsed and stored but never read, renaming or removing it changes nothing on the wire.

POST /auth/magic/verify
{ "email": "[email protected]", "code": "<code from the email>" }

Both fields are required; omitting either is 400 missing_fields. The handler resolves the user by email, matches a row on (userid, hex(SHA-256(code)), provider="email"), checks expiresat, deletes the row, then runs the MFA gate and mints.

The success body is identical in shape to a password login:

{
"token": "v4.public.…",
"refresh_token": "01J…ULID.<base64url-secret>",
"expires_in": 900,
"user": { "id": "U01K…", "email": "[email protected]", "displayname": "…" }
}

A user with TOTP enrolled gets the second-step response instead. A magic link does not bypass a second factor:

{ "mfa_required": true, "mfa_token": "v4.public.…", "methods": ["totp"] }

Complete it at POST /auth/mfa/verify; see Multi-factor authentication.

On a tenant configured for managed sessions the response is the managed shape (session_id, expires_at, user) plus the kis_session cookie, recorded with AAL 1 and auth method magic_link. See Sessions.

Single-use and expiry are enforced by deleting the row on success and by a fail-closed expiry read, a missing, null or non-timestamp expiresat counts as expired rather than as unexpired.

On success the flow emits after_magic_verify and then after_login_success with flow: "magic_link".

StatusCodeCause
400bad_requestBody is not valid JSON
400missing_fieldsemail or code absent
400no_tenantCEPT headers absent
401invalid_magicUnknown email, no matching code hash, expired, or already consumed. One envelope for all four
401invalid_tokenThe identity row disappeared between verify and mint
500engine_unavailableTenant datastore unreachable
500delete_failedCould not consume the row
500mfa_lookup_failedCould not read the TOTP enrolment
500sign_failed / issue_failedToken signing or refresh persistence failed

Managed-session tenants can additionally return 503 policy_unavailable, 500 session_service_unavailable, 409 session_limit and 500 session_failed. The full list is on the error reference.

  • Email only. The request body carries email, and optionally realm; the stored provider is the constant "email"; the sink channel is the literal "email". There is no SMS, WhatsApp, push or in-app magic link.
  • Magic link is the one-time-code login that ships. There is no separate SMS or WhatsApp OTP provider.
  • Realm-aware. realm on the request and on verify names the realm. With none named, the default realm if it offers magic link, otherwise the one realm that does. A realm that does not offer it answers 403 provider_not_allowed, and a choice between several 400 realm_required.
  • TTL is fixed at 15 minutes in the deployable service. No YAML key sets it; the override is a Go option the service never calls.
  • The stored approved flag is written false and never read, and the entity’s numbers column is neither written nor read. Verification matches on the code hash and expiry alone.
  • The row’s realm column holds the tenant key, not the authentication realm.
  • before_magic_verify is a declared event that nothing emits. A hook registered on it never fires; gate the flow at before_magic_request instead.

WebAuthn needs a relying party: the domain a passkey is bound to, and the origins the sign-in page is served from. Each tenant is its own relying party. Set it with a webauthn: block on the tenant’s node, or on iam’s cluster node for every tenant that sets none of its own:

webauthn:
rp_id: example.com # the bare domain: no scheme, port or path
rp_name: Example # shown in the authenticator's dialog; defaults to rp_id
origins: ["https://app.example.com"] # https, or http for localhost

Every origin’s host is rp_id or a subdomain of it. A tenant whose block fails these checks gets 503 webauthn_misconfigured on the four routes, and the server log names the reason; other tenants are unaffected. A tenant with no block, when the cluster node sets none either, gets 503 webauthn_disabled. Both blocks are read at each ceremony, so a change applies without a restart. See Configuration.

MethodPathAuth
POST/auth/webauthn/register/beginauthenticated
POST/auth/webauthn/register/finishauthenticated
POST/auth/webauthn/assert/beginpublic
POST/auth/webauthn/assert/finishpublic

The rest of this section describes the flow and its credential schema.

register/begin takes {"name": "<label for the authenticator>"} from an authenticated caller, loads that user’s existing credentials, starts the ceremony, and persists the challenge in webauthn_session under the name register:<name>:

{ "session_id": "01J…", "options": { "publicKey": { "challenge": "…", "rp": { "id": "…" } } } }

register/finish takes {"session_id", "response"}, response being the raw authenticator attestation JSON, validates it against the stored challenge, writes a webauthn_credential row (userid, name stripped of the register: prefix, credential_id, the serialized credential, and the tenant key in the realm column), and deletes the session row. The response body is {"ok": true}; the credential id is not returned, despite what the handler’s own comment says. It is carried on the after_webauthn_register event as base64url.

assert/begin takes {"email"}, resolves the user, loads their credentials, and stores the challenge under assert:<userid>. It returns the same {session_id, options} envelope. An email that matches no user and a user with no registered credentials both return 401 no_credentials.

assert/finish takes {"session_id", "response"}, rejects a session id whose stored name is not an assert: session, validates the assertion, deletes the session row, emits after_webauthn_assert, runs the MFA gate, and mints, the success and MFA-required bodies are identical to the magic-link ones. A failed assertion emits after_login_failure with reason webauthn_invalid_credential. In managed mode the session records AAL 2 and auth method webauthn.

StatusCodeCause
503webauthn_disabledNo relying party is set for the tenant, on its node or the cluster node
503webauthn_misconfiguredThe tenant’s relying party fails its checks; the server log names the reason
401auth_requiredA register route called with no credential
400missing_fieldsname, email, or session_id absent
400no_tenantCEPT headers absent on an assert route
403hook_deniedA before_webauthn_register or before_webauthn_assert hook aborted
401invalid_sessionCeremony session not found, or an assert-finish presented a register session
401no_credentialsNo credentials for this account, or the email matches no user
400invalid_responseAuthenticator response body could not be parsed
401webauthn_finish_failedAttestation or assertion verification failed
500engine_unavailable / user_load_failed / webauthn_begin_failed / session_persist_failed / persist_failedDatastore or ceremony-library failure
  • No discoverable-credential / autofill login. assert/begin requires an email; the credential row stores no user handle, so a username-less ceremony is not possible.
  • User verification is fixed at the library default of preferred. There is no option requiring UV, so an assertion is not guaranteed to carry a verified user.
  • Credentials per user are capped at 50 on load, silently. A user with more registered authenticators will find some of them never offered, and a credential whose stored JSON fails to parse is skipped without error.
  • Ceremony sessions are never expired or swept. webauthn_session rows carry no expiry check on load and no sweeper runs; an abandoned ceremony leaves its challenge in the table indefinitely. Rows are removed only when a finish call succeeds.
  • Realm-aware, like magic link: realm on the assert begin names the realm, with the same default as magic link, and registration uses the realm of the caller’s token. The realm column on webauthn_credential holds the tenant key.
  • Not usable as a second factor. The MFA gate has exactly one method, TOTP; a registered passkey does not satisfy it.