From ce650a69d46db9e77ba4ebdcd0f1670ea597e504 Mon Sep 17 00:00:00 2001 From: Jesse Wierzbinski Date: Fri, 21 Nov 2025 10:59:28 +0100 Subject: [PATCH] feat(packages/client): :sparkles: Add SSO login helper to client --- packages/client/versia/client.ts | 38 ++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/packages/client/versia/client.ts b/packages/client/versia/client.ts index 8c57d27a..636dd676 100644 --- a/packages/client/versia/client.ts +++ b/packages/client/versia/client.ts @@ -2814,6 +2814,44 @@ export class Client extends BaseClient { ); } + public startSsoLogin( + issuer: string, + client_id: string, + redirect_uri: URL, + options?: Partial<{ + scopes: string[]; + state: string; + }>, + extra?: RequestInit, + ): Promise { + return this.post( + `/oauth/sso/${issuer}`, + { + client_id, + redirect_uri: redirect_uri.toString(), + scopes: options?.scopes, + state: options?.state, + }, + extra, + ).then((output) => { + const isRedirect = output.raw.status === 302; + + if (!isRedirect) { + throw new Error( + `Expected redirect response but got status ${output.raw.status}`, + ); + } + + const location = output.raw.headers.get("Location"); + + if (!location) { + throw new Error("Redirect response missing Location header"); + } + + return new URL(location); + }); + } + // TODO: streamingURL /**