Auth
Who is making this request? Authentication is a pluggable provider on the panel; three ship, and the contract is one function if you need your own. (Whether they may do it is authorization — AUTHORIZATION.md. Portal tokens are a third, separate lane — PORTAL.md.)
The contract
Section titled “The contract”interface Principal { id: string; email?: string; name?: string; roles?: string[]; metadata?: unknown;}
interface AuthProvider { /** The principal, or `null` for "no valid credentials" (→ 401). Throwing → 500. */ authenticate(request: Request): Promise<Principal | null>; /** Optional: the 401 response to send (e.g. with `WWW-Authenticate`). */ challenge?(request: Request): Response | undefined;}Return a Principal to admit, null for “not authenticated” (the panel answers the provider’s
challenge or a plain 401 { error: "Unauthorized" }). A provider that throws is a backend
failure (IdP down) and surfaces as 500, never a misleading 401.
The principal becomes the actor of every control-plane change it makes
({ id, name, email, type: "user" } on grants, overrides and activity entries).
Bundled providers
Section titled “Bundled providers”@xtandard/entitlements/auth/none (default)
Section titled “@xtandard/entitlements/auth/none (default)”import { noAuth, ANONYMOUS_PRINCIPAL } from "@xtandard/entitlements/auth/none";Everyone is anonymous. The default so the five-minute quickstart works — put anything
internet-reachable behind real auth.
@xtandard/entitlements/auth/basic
Section titled “@xtandard/entitlements/auth/basic”import { basicAuth, hashPassword } from "@xtandard/entitlements/auth/basic";
const auth = basicAuth({ realm: "Billing admin", users: [ { username: "ops", passwordHash: await hashPassword("s3cret"), roles: ["admin"] }, { username: "support", passwordHash: process.env.SUPPORT_HASH!, roles: ["support"] }, ],});HTTP Basic with scrypt password hashes (scrypt$<salt>$<hash>, never plaintext at rest),
timing-safe verification, a custom passwordVerifier escape hatch, and a proper
WWW-Authenticate challenge. The CLI / standalone image use it with AUTH_MODE=basic +
AUTH_USERNAME / AUTH_PASSWORD_HASH (+ AUTH_ROLE, default admin).
Generate a hash:
bun -e 'import("@xtandard/entitlements/auth/basic").then(async (m) => console.log(await m.hashPassword(process.argv[1])))' 's3cret'@xtandard/entitlements/auth/delegated
Section titled “@xtandard/entitlements/auth/delegated”import { delegatedAuth } from "@xtandard/entitlements/auth/delegated";
const auth = delegatedAuth({ async authenticate(request) { const session = await myApp.getSession(request); // your cookie / JWT / IdP return session ? { id: session.userId, email: session.email, roles: session.roles } : null; },});The integration point for the auth your app already has — the panel never sees credentials, only
your resolved principal. For service-to-service calls to the runtime API (/api/v1/*), resolve an
API key to a principal with the runtime-service role.
Wiring
Section titled “Wiring”entitlementsPanel({ catalog, auth, // AuthProvider authorization, // see AUTHORIZATION.md portal: { secret }, // optional third lane, see PORTAL.md});Order of evaluation per request:
- Public routes skip auth:
/healthcheck,/api/openapi.json,/api/pricing, the static UI, andPOST /webhooks/:provider(the provider signature is the credential). - A presented
Authorization: Bearer entpt_…token (whenportalis configured) wins — and, if invalid or expired, fails closed with401 { code: "PORTAL_TOKEN" }; it never falls back to host auth. - Otherwise your
authprovider runs.
/config is public too but does authenticate softly: it reports authenticated, the
principal and mode: "admin" | "portal" so the SPA can render the right chrome.