The web/auth package provides the JSON login and logout handlers, plus MFA, magic-link, and passkey HTTP flows. Every handler is built the same way: construct a *Config struct and pass it to a constructor function that returns an http.Handler. There are no functional options (WithX(...)) — all configuration is struct fields, with a Manager/Store (or equivalent) required and everything else defaulted.

Import

Login handler

The internal sequence — including the session-fixation protection folded in after credential validation:
LoginConfig.Manager and .Store are required — LoginHandler panics at construction time if either is nil. Session-fixation protection runs on every successful login (a pre-auth session is migrated to a fresh id, never reused).

Request format

Only a JSON body is accepted — there is no application/x-www-form-urlencoded support.

Success response (default)

Failure response (default)

LoginConfig fields

There is no built-in login rate limiter — front the handler with ratelimit.LoginThrottle yourself (this is what securityhttp.WithLoginThrottle wires up).

Logout handler

LogoutConfig.Store is required (panics if nil). Logout is POST-only (a GET gets 405) and idempotent — an absent or invalid session still clears cookies and returns success.

What happens

  1. Session is invalidated (store.Delete(sessionID)), best-effort
  2. Session cookie is cleared
  3. Remember-me cookie is cleared, if LogoutConfig.RememberMe is set
  4. Response: 200 JSON {"loggedOut": true} (note the field is loggedOut, not logout) — override with LogoutConfig.OnLogout
CSRF is not checked by the handler itself; if you front it with web/csrf.Middleware (or securityhttp.New/NewHandler, which enables CSRF by default once a session store is configured) requests need a valid X-CSRF-Token — see csrf.

MFA handlers

Two-step login: MFALoginHandler runs the primary credential and begins the challenge; MFAStepHandler completes it. Both take an authn.MFAManager (see authn for MFAManagerConfig, MFAFactor, and MFAPolicy).
MFALoginHandler panics if Primary, MFAManager, or Store is nil. MFAStepHandler panics if MFAManager or Store is nil (it does not use Primary).
Issue and consume single-use authentication links via authn.MagicLinkStore (see authn):
emailSender is anything implementing authn.MagicLinkSender:
MagicLinkRequestHandler requires Store and Sender. MagicLinkVerifyHandler requires Store, Manager, and Session.

Passkey handlers

WebAuthn registration and assertion (sign-in), backed by an authn.PasskeyAuthenticator you implement (see authn):
GetUserHandle extracts the WebAuthn user handle for the current caller and is required by both registration handlers:
Mount the registration routes behind session or bearer auth middleware so core.AuthenticationFrom resolves — the handlers return 401 otherwise.