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:
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¶
- 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. - If this tab already verified successfully earlier (
sessionStorageflagpt_auth_verified), skip straight to revealing the page — no network call.sessionStorageclears itself when the tab closes, so a fresh session always re-checks. - Otherwise,
GET https://api.castis.io/api/v1/identity/users/mewithcredentials: "include". 200 OK→ mark verified, reveal the page.401/403→ the access token may have simply expired (15 min TTL) while the refresh token is still good (7 day TTL). TryPOST https://id.castis.io/api/v1/refreshonce, 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.
- now
- 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).
- After a successful login on tellyid, it sends the browser back to the
redirect_uriwith the cookie now set, and the page loads normally.
Making a page public (opt-out)¶
Add front matter to the markdown source:
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_ORIGINincludeshttps://developer.castis.io,AllowCredentials: true. Confirmed live (verified via preflight and real request — both returnaccess-control-allow-originandallow-credentials: true). - AuthAPI —
AUTHAPI_CORS_ORIGINwas updated to includehttps://developer.castis.io(playtelly-iac commitdee66f4, "Allow cors on authapi for developer portal"). Not yet confirmed live as of this writing — a preflight/real request againstid.castis.iowas 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 KubernetesSecretmounted 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
sessionStorageflag 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
useSessionStoreand cross-tabpostSessionMessageon session-expired), this is a page-by-page static site — each page load re-derives its own state independently.
Files changed¶
mkdocs.yml— addedtheme.custom_dir: overrides.overrides/main.html— new file, the guard implementation described above.nginx.conf— unchanged from its original static-serving config (a server-sideauth_requestgate was prototyped and reverted in favor of this client-side approach).
Verification performed¶
nginx -t/ Docker build of the realDockerfile— config and site build cleanly, including the new override and per-pagepublicfront matter (tested against both a normal page and404.html, where MkDocs'pagecontext isNone).- Live
curlagainstapi.castis.ioandid.castis.ioconfirming actual response codes (401with 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
sessionStorageskip 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 actualdeveloper.castis.iodeployment.