Test mode
/v1/test/* exists so an automated suite can drive real auth flows without a
mailbox, an SMS gateway, or a hand-maintained fixture database.
Every operation is refused unless X-Environment names a non-live
environment. Test mode must never touch live data, so this is a hard gate rather
than a convention.
All four calls need an authenticated principal (a project-admin token is the
usual choice) and the X-Environment header.
Read the codes IAM sent
The single most useful one. Returns the out-of-band deliveries recorded for the environment, newest first:
curl -s "https://auth.example.com/v1/test/messages?to=ada@example.com" \
-H "Authorization: Bearer $ADMIN_TOKEN" -H "X-Environment: test"
# -> { "data": [ { "type": "auth.otp.started",
# "payload": { "to": "ada@example.com", "channel": "email",
# "code": "123456", "challenge_id": "…" } } ] }
Filter with channel (email / sms) and to. A test can therefore start a
passwordless sign-in, read the code back, and finish the flow — no provider
needed. It reads recorded events, so it works whether or not a real provider is
configured.
It surfaces the auth.* events, which is what carries a code or a link:
auth.otp.started, auth.magiclink.started, auth.flow.continue and their
.verified counterparts. Email-verification and password-reset codes are not
among them — drive those through the admin API (POST admin/users/{id}/verify-email)
or through the resumable flow instead.
Reset the environment
curl -sX POST https://auth.example.com/v1/test/reset \
-H "Authorization: Bearer $ADMIN_TOKEN" -H "X-Environment: test"
# -> { "ok": true, "deleted": 128 }
Wipes the environment's runtime data — users, sessions, refresh tokens, credentials, factors, recovery codes, identities, challenges, flows, authorization and device codes, activity. Project configuration is left alone, so a suite can reset between runs without reconfiguring.
Seed a user
curl -sX POST https://auth.example.com/v1/test/seed \
-H "Authorization: Bearer $ADMIN_TOKEN" -H "X-Environment: test" \
-H "Content-Type: application/json" \
-d '{"email":"ada@example.com","name":"Ada"}'
Creates an active, email-verified user. Idempotent: seeding the same address
twice is a no-op. Only email (required) and name are read.
Clock
curl -sX POST https://auth.example.com/v1/test/clock \
-H "Authorization: Bearer $ADMIN_TOKEN" -H "X-Environment: test" \
-H "X-Client-Id: prj_7Fk2" -H "Content-Type: application/json" \
-d '{"advance_seconds": 3600}'
# back to real time
curl -sX POST https://auth.example.com/v1/test/clock \
-H "Authorization: Bearer $ADMIN_TOKEN" -H "X-Environment: test" \
-H "X-Client-Id: prj_7Fk2" -H "Content-Type: application/json" -d '{"reset": true}'
The environment's clock runs advance_seconds ahead of real time. Everything
that decides whether something has expired reads that clock, so a test can reach
an expiry instead of waiting for it: OTP and magic-link challenges, resumable
flows, authorization and device codes, sessions and their idle timeout, refresh
tokens, access tokens, PAR request URIs, CSRF tokens, invitations.
Timestamps are still written in real time — the clock moves forward, which is what makes what was issued earlier expire.
The offset applies to the whole environment, including the token you are calling
with. Advance past your admin token's expiry and the next call is a 401. Reset
the clock, or mint a longer-lived token for the test run.
Live is never affected: the offset is refused for live, and the request path
does not even look for one unless the request names a non-live environment.