// Signing in for another T5DE site (OpenID Connect, docs/music.md). The hub's authorize endpoint sends people who // aren't signed in to /signin with the site's request and a signature; once they're signed in, this sends them back // to the authorize endpoint with the same request, which then returns them to the site. type Params = Record; /** The provider's own parameters on the sign-in page, not part of the site's request. */ const internal = new Set(["sig", "exp", "ba_iat", "ba_param", "next", "error"]); /** Where to go once signed in, if the sign-in page was opened for a site's request (else undefined). */ export function continueURL(params: Params): string | undefined { if (typeof params.sig !== "string" || typeof params.client_id !== "string") return undefined; const q = new URLSearchParams(); for (const [k, v] of Object.entries(params)) { if (internal.has(k) || v === undefined) continue; for (const one of Array.isArray(v) ? v : [v]) q.append(k, one); } return `/api/auth/oauth2/authorize?${q}`; } /** The site's client ID, if the page was opened for one. */ export const requestingClient = (params: Params) => (typeof params.client_id === "string" ? params.client_id : undefined); /** Whether the site asked to go straight to a sign-in provider (Music's "Sign in with Discord"). */ export const requestedProvider = (params: Params) => (typeof params.t5de_provider === "string" ? params.t5de_provider : undefined);