Auth and setup API
Log in, manage passwords, sessions and API keys, and finish a site's setup over HTTP.
All paths are on the site's host. Bodies are JSON. A cookie session must send x-cardinal-csrf on every POST, PUT, PATCH and DELETE, and a guest's unsafe request must be JSON. API-key requests need no CSRF token.
The session cookie is __Host-cardinal_sid over https and cardinal_sid over http.
Sign in and out
| Method and path | Body | Answers |
|---|---|---|
POST /api/auth/login | {login, password} | {user, site, csrf_token} and the session cookie. 401 on a bad pair, 429 with Retry-After after too many failures |
POST /api/auth/logout | {ok: true}, and clears the cookie | |
GET /api/auth/me | {user, setup_state, site, csrf_token}. 401 for a guest |
curl -X POST https://erp.acme.com/api/auth/login -c cookies.txt \
-H 'Content-Type: application/json' \
-d '{"login": "jane@acme.com", "password": "..."}'API keys
POST /api/auth/keys with {user} gives that User a new key pair. It needs a signed-in caller with write on the User's API key field. The answer {api_key, api_secret} is the only place the secret appears. Send the pair as Authorization: token KEY:SECRET, Bearer KEY:SECRET or Basic auth.
Passwords
| Method and path | Who | Body | Does |
|---|---|---|---|
POST /api/auth/password/strength | Anyone | {password, user_inputs} | Scores a password. 30 a minute per IP |
POST /api/auth/password/reset | Anyone | {email} | Queues a reset mail. Same answer whether or not the address has an account |
POST /api/auth/password/update | Anyone with a link | {key, new_password} | Sets the password from a reset, welcome or invitation link, then signs in. 410 for a used or expired link |
POST /api/auth/password/change | Signed in | {old_password, new_password} | Changes the caller's password |
POST /api/auth/password/verify | Signed in | {password} | Checks the caller's password |
change and verify count against the login lockout. Reset requests are limited per address and per IP to System Settings' password_reset_limit an hour (3 by default).
A weak new password is accepted with password_warning set to the sentence to show, unless System Settings' enforce_password_strength is on.
Sessions
| Method and path | Does |
|---|---|
GET /api/auth/sessions | The caller's sessions |
DELETE /api/auth/sessions/:id | Ends one. Ending the current one also clears the cookie |
POST /api/auth/sessions/revoke-others | Ends every session but the current one |
Ending a session closes its realtime sockets.
Setup
| Method and path | Who | Does |
|---|---|---|
GET /api/setup/state | Anyone | {setup_state} |
GET /api/setup/regional-data | Anyone | Enabled languages, every Country with its time zones, currency and formats, and a sample number and date in each. 30 a minute per IP |
POST /api/setup/complete | Anyone on an unclaimed site, a System Manager after | Finishes setup and signs the first user in. 409 once the site is set up. 30 a minute per IP |
Other public endpoints
| Method and path | Does |
|---|---|
POST /api/website/language | {language} sets the preferred_language cookie to an enabled Language's code |
GET /api/email/unsubscribe?token= | A mail's signed unsubscribe link. Shows a confirm page |
POST /api/email/unsubscribe?token= | Unsubscribes. Exempt from CSRF, since the signed token is the proof |
POST /api/telegram/webhook | The site's Telegram bot updates, checked by the secret token Telegram sends |
GET or HEAD /health | 200 ok while Postgres answers, 503 db otherwise. Needs no site host |