Skip to content

Docs site login gate

Summary

developer.castis.io (this MkDocs site) is gated behind the same login session used by every other Playtelly app — no separate credentials, no Zitadel OIDC client for the docs site itself, no server-side changes. Gating happens entirely client-side via a script injected into every page's <head>.

Why client-side, not server-side (nginx)

MkDocs builds a fully static site (see Dockerfile) served by plain nginx with no backend. A server-side gate (nginx auth_request) was considered and prototyped first, but the pattern actually used by every other Playtelly frontend (PlatformConsole, OrgConsole, tellyid, PlayoutAdmin) is a client-side guard that checks session state on load and redirects to the shared login app on failure. This implementation mirrors that pattern exactly, for consistency and because it already has proven CORS/cookie configuration in production.

Architecture

Host Role
developer.castis.io This docs site (static, MkDocs Material)
playtelly.castis.io tellyid — the shared login frontend
id.castis.io AuthAPI — issues/refreshes the session cookie
api.castis.io CoreAPI — validates the session, used as the identity check

All hosts share the castis.io apex domain, so the access_token / refresh_token cookies AuthAPI issues (HttpOnly, SameSite=Lax, Domain=.castis.io) are automatically sent on requests to any of them.

How it works

Implemented as a MkDocs Material theme override at overrides/main.html, wired in via mkdocs.yml:

theme:
  name: material
  custom_dir: overrides

This extends Material's base.html and injects into the extrahead block, so it lands in the <head> of every built page.

Flow, per page load

  1. A <style>html{visibility:hidden}</style> tag hides the page immediately — CSS is applied before any paint, so there's no flash of unstyled content while the check runs. A <noscript> fallback reveals the page for visitors with JavaScript disabled.
  2. If this tab already verified successfully earlier (sessionStorage flag pt_auth_verified), skip straight to revealing the page — no network call. sessionStorage clears itself when the tab closes, so a fresh session always re-checks.
  3. Otherwise, GET https://api.castis.io/api/v1/identity/users/me with credentials: "include".
  4. 200 OK → mark verified, reveal the page.
  5. 401/403 → the access token may have simply expired (15 min TTL) while the refresh token is still good (7 day TTL). Try POST https://id.castis.io/api/v1/refresh once, then retry the identity check exactly once more:
    • now 200 OK → mark verified, reveal.
    • still 401/403 → genuinely logged out → window.location.href = "https://playtelly.castis.io/auth?redirect_uri=" + <this exact page>.
    • anything else → show the "can't reach the auth service" retry screen.
  6. Any other failure (network error, CORS failure, 5xx, timeout) at any point → show the retry screen, never redirect. This prevents a backend outage from looping the user through the login page forever (their session may be perfectly fine — the backend is just unreachable).
  7. After a successful login on tellyid, it sends the browser back to the redirect_uri with the cookie now set, and the page loads normally.

Making a page public (opt-out)

Add front matter to the markdown source:

---
public: true
---

This sets IS_PUBLIC_PAGE = true for that page, which skips the guard entirely — no network call, immediate render. No page uses this today; every page is guarded by default (mirrors PlayoutAdmin's PUBLIC_PATHS pattern, kept empty there too).

Endpoints used

Method URL Purpose
GET https://api.castis.io/api/v1/identity/users/me Session/identity check (cookie-based)
POST https://id.castis.io/api/v1/refresh Silently mint a new access token from the refresh token
— https://playtelly.castis.io/auth?redirect_uri=<page> Login page (browser redirect only, not fetched)

/api/v1/token/introspect on AuthAPI was not used — it always returns 200 OK with {"active": false/true} in the body rather than a real 401, which doesn't fit a status-code-based check.

CORS requirements

Both api.castis.io and id.castis.io must allow https://developer.castis.io with credentials:

  • CoreAPI — CORS_ORIGIN includes https://developer.castis.io, AllowCredentials: true. Confirmed live (verified via preflight and real request — both return access-control-allow-origin and allow-credentials: true).
  • AuthAPI — AUTHAPI_CORS_ORIGIN was updated to include https://developer.castis.io (playtelly-iac commit dee66f4, "Allow cors on authapi for developer portal"). Not yet confirmed live as of this writing — a preflight/real request against id.castis.io was missing the CORS headers, meaning the change likely hasn't rolled out yet (ArgoCD sync and/or a pod restart may be needed, since it's a Kubernetes Secret mounted as env vars — those don't hot-reload). Action item: confirm this is live before relying on the refresh step in production. Until it is, an expired access token will surface the "can't reach the auth service" retry screen instead of silently refreshing.

Known limitations / trade-offs

  • Cached verification doesn't track real session state. The sessionStorage flag only clears when the tab closes — not when the actual token expires or is explicitly revoked (logout, "logout all sessions," account disabled). A revoked session can keep browsing cached-as-verified docs pages until the tab is closed. Accepted as a reasonable trade-off for read-only documentation content; revisit with a short TTL on the flag (e.g. matching the 15-minute access token lifetime) if tighter correctness is needed.
  • No ongoing session-store / multi-tab broadcast. Unlike the SPA apps (which use a persistent app shell with useSessionStore and cross-tab postSessionMessage on session-expired), this is a page-by-page static site — each page load re-derives its own state independently.

Files changed

  • mkdocs.yml — added theme.custom_dir: overrides.
  • overrides/main.html — new file, the guard implementation described above.
  • nginx.conf — unchanged from its original static-serving config (a server-side auth_request gate was prototyped and reverted in favor of this client-side approach).

Verification performed

  • nginx -t / Docker build of the real Dockerfile — config and site build cleanly, including the new override and per-page public front matter (tested against both a normal page and 404.html, where MkDocs' page context is None).
  • Live curl against api.castis.io and id.castis.io confirming actual response codes (401 with no cookie, CORS preflight headers present/absent as noted above).
  • In-browser check (via a local container) confirming: no JS errors, the CSS-based hide eliminates the unstyled-content flash, the sessionStorage skip avoids a second network call on a subsequent page, and the redirect/retry logic runs without crashing. The successful-login → redirect-back leg could not be exercised locally (needs a real cookie and the whitelisted production origin) — this needs a final check on the actual developer.castis.io deployment.