0
login with oauth authorization flow
One script reply has been approved by the moderators Verified
Created by admin 244 days ago Viewed 3685 times
0
Submitted by admin Typescript (fetch-only)
Verified 244 days ago
1
/**
2
 * login with oauth authorization flow
3
 *
4
 */
5
export async function main(
6
  client_name: string,
7
  body: { code?: string; state?: string; [k: string]: unknown }
8
) {
9
  const url = new URL(`${BASE_URL}/api/oauth/login_callback/${client_name}`);
10

11
  const response = await fetch(url, {
12
    method: "POST",
13
    headers: {
14
      "Content-Type": "application/json",
15
      Authorization: "Bearer " + WM_TOKEN,
16
    },
17
    body: JSON.stringify(body),
18
  });
19
  if (!response.ok) {
20
    const text = await response.text();
21
    throw new Error(`${response.status} ${text}`);
22
  }
23
  return await response.text();
24
}
25