Postream

Loading the index…

Docs: Authentication

Authentication

Each site has secret sk_ keys for the server and publishable pk_ keys for the browser, shown only once.

Every request carries one of the site's keys in the Authorization header:

GET /public/v1/sites/7c0e…/posts HTTP/1.1
Authorization: Bearer sk_...

With no key, or with an invalid or revoked key, the API answers 401:

{ "statusCode": 401, "code": "UNAUTHENTICATED" }

Two kinds of key

KindPrefixWhere to use itRestriction
Secretsk_Server only: server components, route handlers, build.Refused with 403 SECRET_KEY_IN_BROWSER if the request comes from a browser (with Origin), unless the site allows it.
Publishablepk_Browser code.Only works on pages of the site's allowed domains; with no origin, 403 ORIGIN_NOT_ALLOWED. Lower rate limit, per key and IP.

The recommended path is the secret key on the blog's server, on the per-site route, which is kept at the Cloudflare edge. The publishable key exists for those who need to call the API from the browser.

pst_ keys created before the two kinds keep working, as secret keys.

Generate a key

In the panel, under Public API, with the site selected at the top: name the key, choose the kind and click to generate it. The same screen shows the site id (siteId), used on the per-site route.

Each site can have up to 5 active keys of each kind. The list shows the name, the kind, the start of the key, when it was created and when it was last used.

Swap a key without downtime

  1. Click Rotate: Postream generates a new key with the same kind and name. The old one keeps working for 24 hours (the panel shows until when).
  2. Swap it in the blog and deploy within that window.

For a leaked key, use Revoke: it takes effect right away, and the key starts answering 401.

Usage alerts

The panel warns you, with the origin and how many times it happened, when:

  • a secret key arrives with a browser Origin: it is probably in the site's code. Rotate it and move the call to the server;
  • a publishable key is used outside the allowed domains.