Authentication
Session cookie with CSRF, Bearer tokens and API keys, how to obtain each, and which endpoints need which.
Public read endpoints need no credential. Everything under /api/v1/admin works with any of three credentials through the same middleware, so a script can do what the admin panel does.
| Credential | Header or cookie | Best for |
|---|---|---|
| Session | Cookie hydro_session plus X-CSRF-Token on unsafe methods | The admin SPA and same-origin browser code. |
| Bearer token | Authorization: Bearer hyd_… | Personal scripts and tooling acting as you. |
| API key | X-API-Key: hyd_… | Frontends, SSR servers and CI. Read-only. |
Session cookie and CSRF
Sign in with e-mail, password and, if enabled, a TOTP code. The server sets an HTTP-only hydro_session cookie and a hydro_csrf cookie. For every POST, PUT, PATCH and DELETE, echo the CSRF token in the X-CSRF-Token header. The token is returned by GET /csrf-token ({"token": "…"}) and by GET /api/v1/admin/me.
# 1. sign in and keep the cookies
curl -c jar.txt -X POST https://cms.example.com/auth/login \
-H 'Content-Type: application/json' \
-d '{"email":"[email protected]","password":"…","mfa_code":""}'
# 2. fetch the CSRF token
TOKEN=$(curl -s -b jar.txt -c jar.txt https://cms.example.com/csrf-token | jq -r .token)
# 3. make a state-changing request
curl -b jar.txt -X POST https://cms.example.com/api/v1/admin/pages \
-H "X-CSRF-Token: $TOKEN" -H 'Content-Type: application/json' \
-d '{ … }'Bearer tokens (personal)
A personal token acts as its owner with their assigned role and permissions. Create one in the admin under My Account or via the API from a browser session (tokens cannot mint tokens). The plaintext token is shown once.
curl -X POST https://cms.example.com/api/v1/admin/account/tokens \
-b jar.txt -H "X-CSRF-Token: $TOKEN" -H 'Content-Type: application/json' \
-d '{"name":"deploy script","expires_in_days":90}'
# -> { "data": { "token": "hyd_…", "item": { "id": "…", "prefix": "hyd_ab12" } } }
curl https://cms.example.com/api/v1/admin/me -H 'Authorization: Bearer hyd_…'expires_in_days is optional (omit or 0 for no expiry, maximum 3650). List with GET /api/v1/admin/account/tokens and revoke with DELETE /api/v1/admin/account/tokens/{id}.
API keys
API keys are for machines. They are read-only and carry one scope. Only administrators create them (POST /api/v1/admin/api-keys, also available in the admin).
| Scope | Allows |
|---|---|
read | Read endpoints. |
preview | Read endpoints, and viewing unpublished content once handlers honour it (draft preview). |
curl -X POST https://cms.example.com/api/v1/admin/api-keys \
-b jar.txt -H "X-CSRF-Token: $TOKEN" -H 'Content-Type: application/json' \
-d '{"name":"frontend ssr","scope":"read","expires_in_days":365}'
curl https://cms.example.com/api/v1/admin/me -H 'X-API-Key: hyd_…'Authorization: Bearer hyd_… or X-API-Key) is authoritative: when one is present the session cookie is ignored. Because these requests do not rely on cookies, they do not need a CSRF token.Staff mobile tokens
Native apps can sign staff in with POST /api/v1/mobile/auth/login (email, password, optional mfa_code, device_id, device_name, platform) and renew with /api/v1/mobile/auth/refresh. revoke and revoke-all end one or all device sessions. Members use the parallel /api/v1/mobile/member/auth/* family, see Member API.
Credential cheat sheet
| I want to… | Use |
|---|---|
| Read published content in my SSR app | No credential needed; an API key read is optional and lets you separate traffic. |
| Preview drafts in my frontend | API key preview or a signed preview link. See Draft previews. |
| Script imports and edits | Personal Bearer token. |
| Let the admin SPA work | Session cookie plus CSRF (automatic). |