caelum0x 977520fc00 feat(console): Mint billing accounts, OIDC SSO for Rithub, Relay vs. OpenRouter page
- Apps tab: one-click Mint ledger account per app (POST /v1/accounts
  already existed on Mint; the gap was the UI), db/migrations/0012.
- Console is now a real OIDC provider for Rithub (Gitea) SSO: RS256
  id_token + self-contained access_token over the authorization-code
  grant, single-use codes (db/migrations/0013), discovery/jwks/
  authorize/token/userinfo routes. A visitor who isn't signed in yet
  is bounced through existing sign-in and lands back on /oidc/authorize
  automatically. Gated on RAILYARD_OIDC_SIGNING_KEY/RAILYARD_OIDC_CLIENTS
  (scripts/gen-oidc-key.mjs generates the former); unset, every /oidc/*
  route is a clean 503.
- Public, numbers-backed /compare/relay-vs-openrouter page with a
  spend-tier pricing table and a Console-signup CTA using the existing
  cross-sell attribution bridge.

Verified: tsc clean, full `npm test` (167) and `npm run test:bundle`
(3) green; a scratch script exercised the OIDC code/token/userinfo
flow end to end against real generated RSA keys (found and fixed a
missing email_verified claim); `next dev` used to curl every new
route live (discovery, jwks, authorize's 400s and sign-in detour,
token validation, userinfo auth, the comparison page, the mint-account
API).
2026-10-23 16:52:45 +03:00

17 lines
850 B
TypeScript

// GET /oidc/userinfo (backlog item 5): verifies the access_token minted by
// /oidc/token and returns the same claims as the id_token.
import { deps } from "../../../lib/deps.ts";
import { json } from "../../../lib/http.ts";
import { userinfo } from "../../../lib/oidc.ts";
export async function GET(req: Request) {
const { cfg } = deps();
if (!cfg.oidc) return json({ error: "invalid_request" }, 503);
const auth = req.headers.get("authorization");
if (!auth?.startsWith("Bearer ")) return new Response(null, { status: 401, headers: { "www-authenticate": 'Bearer realm="railyard-oidc"' } });
const claims = await userinfo(cfg.oidc, auth.slice(7), cfg.consoleUrl);
if (!claims) return new Response(null, { status: 401, headers: { "www-authenticate": 'Bearer realm="railyard-oidc", error="invalid_token"' } });
return json(claims);
}