| 1 | import { data } from "react-router"; |
| 2 | |
| 3 | import { ssoAddresses } from "@g1t/contracts"; |
| 4 | |
| 5 | import type { Route } from "./+types/auth-sso-metadata"; |
| 6 | import { sso } from "../lib/sso.server"; |
| 7 | |
| 8 | /** |
| 9 | * g1t's SAML service provider metadata for a workspace, for its identity |
| 10 | * provider to read: the entity id (this address) and where to post the |
| 11 | * response. The same for everyone; it says nothing about the workspace. |
| 12 | */ |
| 13 | export async function loader({ request, params }: Route.LoaderArgs) { |
| 14 | // Keyed by the workspace's id, whatever names it here. |
| 15 | const summary = await sso.summary(params.owner.toLowerCase()); |
| 16 | if (!summary.workspace_id) throw data("No such workspace.", { status: 404 }); |
| 17 | const addresses = ssoAddresses(new URL(request.url).origin, summary.workspace_id, summary.slug); |
| 18 | const xml = await sso.metadata(addresses.entityId, addresses.acsUrl); |
| 19 | return new Response(xml, { |
| 20 | headers: { |
| 21 | "content-type": "application/samlmetadata+xml; charset=utf-8", |
| 22 | "cache-control": "public, max-age=3600", |
| 23 | "content-disposition": `inline; filename="g1t-${summary.workspace_id}-metadata.xml"`, |
| 24 | }, |
| 25 | }); |
| 26 | } |