-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathoauth.ts
More file actions
31 lines (28 loc) · 1.01 KB
/
oauth.ts
File metadata and controls
31 lines (28 loc) · 1.01 KB
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
import { GetBackendUrl, GetJson, PostJson } from './base';
import type { LoginOkResponse, OAuthFinalizeRequest, OAuthSignupData } from './models';
import { TransformLoginOkResponse, TransformOAuthSignupData } from './transformers';
export function GetOAuthAuthorizeUrl(provider: string, flow: 'LoginOrCreate' | 'Link') {
const providerEnc = encodeURIComponent(provider);
const flowEnc = encodeURIComponent(flow);
return GetBackendUrl(`1/oauth/${providerEnc}/authorize?flow=${flowEnc}`);
}
export async function OAuthSignupGetData(provider: string) {
const providerEnc = encodeURIComponent(provider);
return GetJson<OAuthSignupData>(
`1/oauth/${providerEnc}/signup-data`,
200,
TransformOAuthSignupData
);
}
export async function OAuthSignupFinalize(
provider: string,
payload: OAuthFinalizeRequest
): Promise<LoginOkResponse> {
const providerEnc = encodeURIComponent(provider);
return PostJson(
`1/oauth/${providerEnc}/signup-finalize`,
payload,
200,
TransformLoginOkResponse
);
}