()
| 191 | } |
| 192 | |
| 193 | export async function requestUserCode(): Promise<DeviceCodeResponse> { |
| 194 | const response = await fetch(`${issuerPath("/api/accounts/deviceauth/usercode")}`, { |
| 195 | method: "POST", |
| 196 | headers: { |
| 197 | "Content-Type": "application/json", |
| 198 | }, |
| 199 | body: JSON.stringify({ |
| 200 | client_id: Config.clientId, |
| 201 | }), |
| 202 | }) |
| 203 | |
| 204 | if (!response.ok) { |
| 205 | const text = await response.text() |
| 206 | throw new Error(`Failed to request user code: ${response.status} - ${text}`) |
| 207 | } |
| 208 | |
| 209 | const body = await response.json() |
| 210 | const deviceAuthId = body.device_auth_id |
| 211 | const userCode = body.user_code |
| 212 | if (!deviceAuthId || !userCode) { |
| 213 | throw new Error("Received invalid response when requesting device code") |
| 214 | } |
| 215 | |
| 216 | return { |
| 217 | deviceAuthId, |
| 218 | userCode, |
| 219 | interval: parseInterval(body.interval), |
| 220 | verificationUri: DEVICE_LOGIN_URL, |
| 221 | } |
| 222 | } |
| 223 | |
| 224 | export function printDeviceCodePrompt(code: string, verificationUrl = DEVICE_LOGIN_URL): void { |
| 225 | console.log(` |
no test coverage detected