Authentication & Tokens
Headless ships five composable authentication modes (Totoglu\Headless\Auth\AuthMode) plus signed preview tokens for viewing unpublished pages and draft entries safely.
All 5 AuthMode Guards
Section titled “All 5 AuthMode Guards”AuthMode |
Guard Class | Header / Mechanism | Best For |
|---|---|---|---|
AuthMode::Public |
N/A | No auth header required | Public catalogs, marketing pages, OpenAPI schemas |
AuthMode::ApiKey |
ApiKeyGuard |
X-Api-Key: whk_... or Authorization: Bearer whk_... |
Server-to-server builds, static site generators, partner integrations |
AuthMode::BearerJwt |
BearerJwtGuard |
Authorization: Bearer <hs256-jwt> issued by POST /auth/login or issueJwtToken() |
Mobile apps and SPAs using short-lived JWTs + rotating whr_* refresh tokens |
AuthMode::Hmac |
HmacGuard |
X-Headless-Signature, X-Headless-Timestamp, X-Headless-Nonce |
High-security server-to-server integrations requiring body integrity + replay protection |
AuthMode::Session |
SessionCookieGuard |
Logged-in ProcessWire session + X-CSRF-Token on POST/PUT/PATCH/DELETE |
Same-origin hybrid frontends and admin preview widgets |
1. Personal Access Tokens (whk_*)
Section titled “1. Personal Access Tokens (whk_*)”Each key binds a ProcessWire user, explicit scopes (e.g., pages:read, entries:read, pages:write), an optional custom rate limit, and an expiration date. Only key_prefix and key_hash are persisted.
2. JWT Access Tokens & Rotating Refresh Tokens (whr_*)
Section titled “2. JWT Access Tokens & Rotating Refresh Tokens (whr_*)”POST /api/v1/auth/login: Exchanges ProcessWire credentials (throttled) for an HS256 JWT (jwt_ttl, default3600s) and awhr_*refresh token (refresh_ttl).POST /api/v1/auth/refresh: Atomically consumes and rotates thewhr_*token; if a previously consumed token is replayed, reuse detection revokes the user’s token family immediately.POST /api/v1/auth/logout&GET /api/v1/auth/me: Revoke the active refresh token or inspect the activeHeadlessPrincipal(id,name,email,scheme,scopes,roles).
3. HMAC Signatures (HmacGuard) & Preview Tokens
Section titled “3. HMAC Signatures (HmacGuard) & Preview Tokens”HmacGuard: VerifiesX-Headless-Signature,X-Headless-Timestamp(default300stolerance), andX-Headless-Nonce, recording used nonces inWireCache(HlSecurity) to prevent replay attacks. Compute signatures in PHP withHmacGuard::computeSignature().- Preview Tokens: Issue time-limited draft/unpublished preview tokens via
$headless->issuePreviewToken($target, 3600, 'pages')and pass?preview_token=...onGET /pages/{id}orGET /entries/{type}/{id}.