AI Engineering Workspace
PartialChat, files, terminal and preview in one place. Chat sessions run on a durable Postgres-backed queue (chat only: no tools or shell). Live models need an API key; the terminal is unavailable.
Project files
read-onlyapp/src/lib/oidc.ts
1// Zoo IAM (Keycloak realm "zoo") OIDC client wiring. Pure verification lives in oidc-core.mjs; this file does the I/O.2import fs from "node:fs"; import os from "node:os"; import path from "node:path";3import { resolveConfig } from "./config";4import { getSetting } from "./db";5import { CLIENT_ID, DEFAULT_ISSUER, validateDiscovery } from "./oidc-core.mjs";67const SECRET_FILE = process.env.ZCS_OIDC_SECRET_FILE || path.join(os.homedir(), ".config/zoo-cloud-studio/oidc-client-secret");8const loopback = () => process.env.ZCS_OIDC_ALLOW_HTTP_LOOPBACK === "1"; // test harness only; never set in production9export async function oidcConfig() {10 const c = await resolveConfig(); const issuer = (c.OIDC_ISSUER.value || DEFAULT_ISSUER).replace(/\/$/, "");11 let secret = process.env.OIDC_CLIENT_SECRET || ""; try { if (!secret) secret = fs.readFileSync(SECRET_FILE, "utf8").trim(); } catch {}12 return { issuer, clientId: CLIENT_ID, redirectUri: c.OIDC_REDIRECT_URI.value, secret, configured: !!secret, requireAcr: await getSetting("oidc.required_acr", "") || undefined };13}14const cache: { disc?: { at: number; v: any }; jwks?: { at: number; v: any } } = {};15async function getJson(url: string) { const r = await fetch(url, { signal: AbortSignal.timeout(10_000), headers: { accept: "application/json" } }); if (!r.ok) throw new Error(`HTTP ${r.status} from IdP`); return r.json(); }16export async function discovery(issuer: string) {17 if (cache.disc && Date.now() - cache.disc.at < 600_000) return cache.disc.v;18 const v = validateDiscovery(await getJson(`${issuer}/.well-known/openid-configuration`), issuer, { allowHttpLoopback: loopback() }); cache.disc = { at: Date.now(), v }; return v;19}20/** JWKS is cached 10 min and refetched once when a kid is unknown (key rotation). */21export async function jwks(issuer: string, force = false) {22 if (!force && cache.jwks && Date.now() - cache.jwks.at < 600_000) return cache.jwks.v;23 const v = await getJson((await discovery(issuer)).jwks_uri); cache.jwks = { at: Date.now(), v }; return v;24}25export async function withKeys<T>(issuer: string, fn: (k: any) => T): Promise<T> { try { return fn(await jwks(issuer)); } catch (e) { if (!/key|signature/i.test(String((e as Error).message))) throw e; return fn(await jwks(issuer, true)); } }26export async function exchangeCode(cfg: Awaited<ReturnType<typeof oidcConfig>>, code: string, verifier: string) {27 const d = await discovery(cfg.issuer);28 const r = await fetch(d.token_endpoint, { method: "POST", signal: AbortSignal.timeout(10_000), headers: { "content-type": "application/x-www-form-urlencoded", authorization: "Basic " + Buffer.from(`${encodeURIComponent(cfg.clientId)}:${encodeURIComponent(cfg.secret)}`).toString("base64") }, body: new URLSearchParams({ grant_type: "authorization_code", code, redirect_uri: cfg.redirectUri, code_verifier: verifier }) });29 const j = await r.json().catch(() => ({})); if (!r.ok || !j.id_token) throw new Error("token exchange failed"); return j as { id_token: string };30}31
Conversation
PartialSign in to start AI sessions.
Task checklist
- Application shell deployed
- Persistent projects
- Agent runtime
- Sandboxed terminal
Execution activity
No agent sessions. Git HEAD 0eebc42 on master.
Approval requests
None pending.