* Requests a device code from the OAuth server
()
| 147 | * Requests a device code from the OAuth server |
| 148 | */ |
| 149 | async function requestDeviceCode(): Promise<DeviceCodeResponse> { |
| 150 | const serverUrl = getServerUrl(); |
| 151 | const response = await fetch(`${serverUrl}/oauth/device/code`, { |
| 152 | method: "POST", |
| 153 | headers: { |
| 154 | "Content-Type": "application/json", |
| 155 | }, |
| 156 | body: JSON.stringify({} as DeviceCodeRequest), |
| 157 | }); |
| 158 | |
| 159 | if (!response.ok) { |
| 160 | const errorText = await response.text(); |
| 161 | throw new Error( |
| 162 | `Failed to request device code: ${response.status} ${errorText}` |
| 163 | ); |
| 164 | } |
| 165 | |
| 166 | return (await response.json()) as DeviceCodeResponse; |
| 167 | } |
| 168 | |
| 169 | /** |
| 170 | * Polls for an access token using the device code |
no test coverage detected