| 1 | import { data, redirect } from "react-router"; |
| 2 | |
| 3 | import type { Route } from "./+types/auth-sso-saml"; |
| 4 | import { page } from "../lib/meta"; |
| 5 | import { clearErrorCookie, readErrorCookie } from "../lib/sso"; |
| 6 | import { sso } from "../lib/sso.server"; |
| 7 | import { SsoProblem } from "./auth-sso"; |
| 8 | |
| 9 | export function meta({ params, ...args }: Route.MetaArgs) { |
| 10 | return page(args, { title: `Single sign-on · ${args.loaderData?.slug ?? params.owner} · g1t` }); |
| 11 | } |
| 12 | |
| 13 | /** |
| 14 | * The assertion consumer service, as a page: the provider's POST is |
| 15 | * answered by the Worker (workers/sso-saml.ts), which comes back here with |
| 16 | * why it did not work. Opened by itself, it starts again. |
| 17 | */ |
| 18 | export async function loader({ request, params }: Route.LoaderArgs) { |
| 19 | const key = params.owner.toLowerCase(); |
| 20 | const slug = (await sso.summary(key).catch(() => null))?.slug || key; |
| 21 | const error = readErrorCookie(request.headers.get("cookie")); |
| 22 | if (!error) throw redirect(`/auth/sso/${slug}`); |
| 23 | return data({ slug, error }, { headers: { "set-cookie": clearErrorCookie() } }); |
| 24 | } |
| 25 | |
| 26 | export default function SsoSaml({ loaderData }: Route.ComponentProps) { |
| 27 | return <SsoProblem slug={loaderData.slug} error={loaderData.error} />; |
| 28 | } |