Passwordless verification
Proof lifecycle, expiry, replay, callbacks and error handling for passwordless sign-in.
This page describes what happens after a magic link or email OTP is sent. Both factors share the same Token store, session creation and error semantics.
The two proof kinds
| Kind | Issued by | Stored form | Carries data |
|---|---|---|---|
TokenMagicLink | token.Service.IssueWithData | SHA-256 digest of the raw token | Email, name, callback URL |
TokenEmailOTP | TokenStore.CreateToken | Digest(email + ":" + code) | Nothing; the email is supplied at verification |
Both kinds are in AllTokenKinds, so every revocation sweep — password change, reset, account
deletion, refresh replay containment — includes them. Neither raw value is ever stored.
Expiry
Passwordless.MagicLinkTTL and Passwordless.OTPTTL default to five minutes and are validated
by New; a negative value returns ErrInvalidPasswordlessConfig. Expiry uses the configured
Clock, so tests can advance time deterministically. An expired proof returns
ErrTokenExpired / invalid_token (401).
Single use and rotation
ConsumeToken is an atomic conditional update, and the digest comparison is constant time.
Once consumed, a proof cannot be used again. Replaying a magic link returns ErrMagicLinkAlreadyUsed / link_already_used (401); replaying
an OTP returns ErrOTPAlreadyUsed / code_already_used (401). A User who tries the same proof
twice knows to request a new one.
Sending a second proof for the same email deletes the previous Token of that kind:
- magic links: keyed by the User ID, or a deterministic proof subject before the User exists;
- email OTPs: keyed the same way.
Only the newest code or link works. The older one fails as an unknown Token.
Callback validation (magic links only)
The callback embedded in the link is authoritative. If a query callback_url is present it must
match the embedded value exactly. The callback must appear in one of these allowlists, in order:
Passwordless.AllowedRedirectsOAuth.AllowedRedirectsAppURLexactly
Matching is exact; a same-origin but unlisted path is rejected with ErrOAuthRedirectNotAllowed
/ invalid_request (400). This is the same rule OAuth uses. Without a callback, verification
returns session JSON instead of redirecting.
Email verification and auto-created Users
A consumed proof marks the email verified. For an existing User, EmailVerified is set to true
and the password and all Sessions are left intact. For an unknown email:
AllowSignUpnil or true: a User is created withEmailVerified = trueand no credential Account. They can set a password later withChangePassword.AllowSignUp = false: the send was a silent success with no proof, so verification cannot succeed.
OnSignUp is not called for passwordless auto-creation, so no hook receives personal data that
it would not get from password sign-up.
Sessions
Verification creates a Session immediately through the same seam password sign-in uses. The idle
and absolute timeouts come from SessionConfig. The Go API returns the raw Session token in
SignInResult.SessionToken; the HTTP API sets the signet_session (or __Host- prefixed)
cookie and the CSRF cookie. To require recent authentication afterwards, use
VerifyFreshSession or RequireFreshSession — freshness is measured from CreatedAt.
Error reference
| Situation | Sentinel | Wire |
|---|---|---|
| Malformed, unknown, rotated or expired magic link | ErrInvalidMagicLink | 401 invalid_link |
| Magic link already consumed | ErrMagicLinkAlreadyUsed | 401 link_already_used |
| Malformed, unknown, wrong-email or expired OTP | ErrInvalidOTP | 401 invalid_code |
| OTP already consumed | ErrOTPAlreadyUsed | 401 code_already_used |
| Callback outside the allowlist or mismatched | ErrOAuthRedirectNotAllowed | 400 invalid_request |
| Send or verify endpoint over its limit | ErrRateLimited | 429 rate_limited |
| Negative configured TTL | ErrInvalidPasswordlessConfig | rejected by New |
| Invalid email address | ErrInvalidEmail | 400 invalid_input |
See Errors for the complete mapping and Security for the controls these flows share.