-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathget-device-code.ts
More file actions
32 lines (28 loc) · 805 Bytes
/
Copy pathget-device-code.ts
File metadata and controls
32 lines (28 loc) · 805 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 {
GITHUB_APP_SCOPES,
GITHUB_BASE_URL,
GITHUB_CLIENT_ID,
standardHeaders,
} from '~/lib/api-config'
import { HTTPError } from '~/lib/error'
import { fetchGitHub } from '~/lib/upstream-fetch'
export async function getDeviceCode(): Promise<DeviceCodeResponse> {
const response = await fetchGitHub(`${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
}