mirror of
https://github.com/versia-pub/server.git
synced 2025-12-06 08:28:19 +01:00
feat(packages/client): ✨ Add SSO login helper to client
This commit is contained in:
parent
5e84fb66f9
commit
ce650a69d4
|
|
@ -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<URL> {
|
||||||
|
return this.post<void>(
|
||||||
|
`/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
|
// TODO: streamingURL
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue