import type { Request, Response, Router } from "express"; import { escapeHtml } from "./opkssh-html.js"; function resultPage(ok: boolean, message: string): string { return `Termix

${ok ? "Signed in" : "Sign-in failed"}

${escapeHtml(message)}

`; } /** * The OIDC redirect target for Step CA sign-ins. Unauthenticated on purpose: * the browser that finishes the sign-in may not be the one running Termix, * so the request is matched to its session by the OAuth state. */ export function registerHostStepCaRoutes(router: Router): void { router.get("/step-ca-callback", async (req: Request, res: Response) => { const { completeStepCaAuth } = await import("../../hosts/step-ca-auth.js"); const stringQuery = (name: string): string | undefined => { const value = req.query[name]; return typeof value === "string" ? value : undefined; }; const result = await completeStepCaAuth({ state: stringQuery("state"), code: stringQuery("code"), error: stringQuery("error"), error_description: stringQuery("error_description"), }); res .status(result.ok ? 200 : 400) .type("html") .send(resultPage(result.ok, result.message)); }); }