Cabinhub News API v1.0.0

Docs / Authentication

Authentication

One bearer key on every route except /v1/health. Four operator routes also want the admin token. Auth failures are decided before the quota check, so a bad key never spends your month.

Source: docs/API.md §3.

Three arms. The app resolves them in this order for a presented bearer.

3.1 Database keys (the customer path)

Issued with backend/scripts/keys.py create --customer vg --plan starter --quota 45000 (or backend/scripts/onboard_customer.py, see docs/OPERATIONS.md §5.4). The key looks like cbn_<random>; only its SHA-256 hash is stored, so a lost key can only be replaced, never recovered. Present it as:

Text
Authorization: Bearer cbn_...

A database key carries a customer, plan and monthly billable-item quota, and every served response is metered against it.

3.2 Legacy env keys

NEWS_API_KEYS (comma separated) still works for backwards compatibility. These keys have no customer identity and no quota; /v1/usage and /v1/usage/history answer 501 for them.

3.3 Dev mode

If NEWS_API_KEYS is unset and the key table was read successfully and holds no rows, the app runs in DEV MODE: every route is open, and one loud warning is logged at startup. This is for local work only. Never leave a deployed box in this state.

Fail closed. An unreadable key table is not "no keys exist". If the count probe throws (SQLite locked, corrupt file, missing schema), authentication stays enforced: a request without a valid bearer answers 401 and no anonymous identity is ever issued. The same rule covers a key table whose last key was revoked. billing.key_count() returns 1 ("configured") on a read failure, and the request path is also structurally guarded (auth.auth_configured), so a probe that raises cannot open the API by accident. Dev mode is therefore reachable only from a successful read that returns zero.

3.4 Admin token

NEWS_ADMIN_TOKEN plus the header X-Admin-Token guards POST /v1/refresh, GET /v1/admin/usage, GET /v1/runs, GET /v1/sources/health and the three /v1/admin/webhooks/* routes (§12, "Webhook delivery admin"). Unset means those routes answer 503 and never run. Verified text: refresh is disabled: NEWS_ADMIN_TOKEN is not configured.

The admin token is never accepted cross-origin: the CORS policy does not allow the X-Admin-Token request header, so /v1/refresh cannot be driven from a browser on another site.

3.5 Failure shapes (verified)

SituationStatusBodyHeaders
No Authorization, auth configured401{"detail":"invalid or missing bearer token"}WWW-Authenticate: Bearer
Wrong bearer401sameWWW-Authenticate: Bearer
Revoked key401{"detail":"this api key has been revoked"}WWW-Authenticate: Bearer
Key table unreadable, no legacy keys configured401{"detail":"invalid or missing bearer token"} (fail closed, never dev mode)WWW-Authenticate: Bearer
/v1/refresh, /v1/admin/usage, /v1/runs, /v1/sources/health with a wrong or missing admin token401{"detail":"invalid admin token"}WWW-Authenticate: X-Admin-Token
/v1/usage, /v1/usage/history with a legacy/dev bearer501{"detail":"usage reporting requires a database-issued key; this bearer is a legacy NEWS_API_KEYS entry with no customer identity"}—

A client bearer is not accepted on the admin routes: GET /v1/runs with a valid client key answers 401 {"detail":"invalid admin token"} (measured). Auth failures never consume quota, because the identity is resolved before the quota check.

Which token each route wants

MethodPathAuth
GET/fxs/v4/culture/allclient bearer
GET/fxs/v4/{culture}/post/{rest}client bearer
GET/fxs/v4/{culture}/tagclient bearer
GET/fxs/v4/{culture}/tag/filter/{tag_ids}client bearer
GET/v1/accountcookie session
DELETE/v1/account/news-botcookie session + X-Requested-With: cabinhub-console
GET/v1/account/news-botcookie session
PUT/v1/account/news-botcookie session + X-Requested-With: cabinhub-console
POST/v1/account/news-bot/refreshcookie session + X-Requested-With: cabinhub-console
POST/v1/account/otpX-Requested-With: cabinhub-console (no session)
DELETE/v1/account/sessioncookie session + X-Requested-With: cabinhub-console
POST/v1/account/sessionX-Requested-With: cabinhub-console (no session)
GET/v1/account/usagecookie session
GET/v1/account/usage/statementcookie session
GET/v1/account/usage/statement.csvcookie session
GET/v1/admin/accountsX-Admin-Token + X-Admin-Actor
POST/v1/admin/accountsX-Admin-Token + X-Admin-Actor
GET/v1/admin/keysX-Admin-Token + X-Admin-Actor
POST/v1/admin/keysX-Admin-Token + X-Admin-Actor
GET/v1/admin/keys/auditX-Admin-Token + X-Admin-Actor
POST/v1/admin/keys/{key_id}/revokeX-Admin-Token + X-Admin-Actor
GET/v1/admin/usageX-Admin-Token
GET/v1/admin/webhooks/deliveriesX-Admin-Token
POST/v1/admin/webhooks/deliveries/{delivery_id}/replayX-Admin-Token
GET/v1/admin/webhooks/summaryX-Admin-Token
GET/v1/digest/{locale}client bearer + quota
GET/v1/digest/{locale}/emailclient bearer + quota
GET/v1/digest/{locale}/email/{day}client bearer + quota
GET/v1/digest/{locale}/{day}client bearer + quota
GET/v1/feed/{locale}client bearer + quota
GET/v1/healthnone
GET/v1/images/{key}client bearer + quota
HEAD/v1/images/{key}client bearer + quota
GET/v1/itemsclient bearer + quota
GET/v1/items/{item_id}client bearer + quota
GET/v1/items/{item_id}/relatedclient bearer + quota
GET/v1/metaclient bearer + quota
POST/v1/refreshclient bearer + X-Admin-Token
GET/v1/runsX-Admin-Token
GET/v1/runs/{run_id}client bearer + quota
GET/v1/searchclient bearer + quota
GET/v1/site/digest/{locale}none
GET/v1/site/digest/{locale}/{day}none
GET/v1/site/feed/{locale}none
GET/v1/site/images/{key}none
HEAD/v1/site/images/{key}client bearer + quota
GET/v1/site/itemsnone
GET/v1/site/items/{item_id}none
GET/v1/site/items/{item_id}/relatednone
GET/v1/site/marketsnone
GET/v1/site/markets/{symbol}/historynone
GET/v1/site/metanone
GET/v1/site/searchnone
GET/v1/site/statusnone
GET/v1/site/storyline/{item_id}none
GET/v1/site/topicsnone
GET/v1/site/topics/{slug}none
GET/v1/sources/healthX-Admin-Token
GET/v1/statsclient bearer + quota
GET/v1/stream/{locale}client bearer + quota
GET/v1/usageclient bearer (no quota check)
GET/v1/usage/historyclient bearer (no quota check)
GET/v1/versionnone

Source: docs/API.md §2 route table, cross-checked against clients/openapi.json.