-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathoauth.ts
More file actions
32 lines (27 loc) · 973 Bytes
/
oauth.ts
File metadata and controls
32 lines (27 loc) · 973 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import { getBackendURL } from '$lib/utils/url';
import { GetJson, PostJson } from './base';
import type { LoginOkResponse, OAuthFinalizeRequest, OAuthSignupData } from './models';
import { TransformLoginOkResponse, TransformOAuthSignupData } from './transformers';
export function GetOAuthAuthorizeUrl(provider: string, flow: 'LoginOrCreate' | 'Link'): string {
const url = getBackendURL(`1/oauth/${encodeURIComponent(provider)}/authorize`);
url.searchParams.set('flow', flow);
return url.href;
}
export async function OAuthSignupGetData(provider: string) {
return GetJson<OAuthSignupData>(
`1/oauth/${encodeURIComponent(provider)}/signup-data`,
200,
TransformOAuthSignupData
);
}
export async function OAuthSignupFinalize(
provider: string,
payload: OAuthFinalizeRequest
): Promise<LoginOkResponse> {
return PostJson(
`1/oauth/${encodeURIComponent(provider)}/signup-finalize`,
payload,
200,
TransformLoginOkResponse
);
}