forked from ericc-ch/copilot-api
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathget-device-code.ts
More file actions
30 lines (26 loc) · 746 Bytes
/
get-device-code.ts
File metadata and controls
30 lines (26 loc) · 746 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
import {
GITHUB_APP_SCOPES,
GITHUB_BASE_URL,
GITHUB_CLIENT_ID,
standardHeaders,
} from "~/lib/api-config"
import { HTTPError } from "~/lib/error"
export async function getDeviceCode(): Promise<DeviceCodeResponse> {
const response = await fetch(`${GITHUB_BASE_URL()}/login/device/code`, {
method: "POST",
headers: standardHeaders(),
body: JSON.stringify({
client_id: GITHUB_CLIENT_ID,
scope: GITHUB_APP_SCOPES,
}),
})
if (!response.ok) throw new HTTPError("Failed to get device code", response)
return (await response.json()) as DeviceCodeResponse
}
export interface DeviceCodeResponse {
device_code: string
user_code: string
verification_uri: string
expires_in: number
interval: number
}