(inputs = {})
| 220 | }, |
| 221 | ], |
| 222 | async authorize(inputs = {}) { |
| 223 | const deploymentType = inputs.deploymentType || "github.com" |
| 224 | |
| 225 | let domain = "github.com" |
| 226 | |
| 227 | if (deploymentType === "enterprise") { |
| 228 | const enterpriseUrl = inputs.enterpriseUrl |
| 229 | domain = normalizeDomain(enterpriseUrl!) |
| 230 | } |
| 231 | |
| 232 | const urls = getUrls(domain) |
| 233 | |
| 234 | const deviceResponse = await fetch(urls.DEVICE_CODE_URL, { |
| 235 | method: "POST", |
| 236 | headers: { |
| 237 | Accept: "application/json", |
| 238 | "Content-Type": "application/json", |
| 239 | "User-Agent": `opencode/${InstallationVersion}`, |
| 240 | }, |
| 241 | body: JSON.stringify({ |
| 242 | client_id: CLIENT_ID, |
| 243 | scope: "read:user", |
| 244 | }), |
| 245 | }) |
| 246 | |
| 247 | if (!deviceResponse.ok) { |
| 248 | throw new Error("Failed to initiate device authorization") |
| 249 | } |
| 250 | |
| 251 | const deviceData = (await deviceResponse.json()) as { |
| 252 | verification_uri: string |
| 253 | user_code: string |
| 254 | device_code: string |
| 255 | interval: number |
| 256 | } |
| 257 | |
| 258 | return { |
| 259 | url: deviceData.verification_uri, |
| 260 | instructions: `Enter code: ${deviceData.user_code}`, |
| 261 | method: "auto" as const, |
| 262 | async callback() { |
| 263 | while (true) { |
| 264 | const response = await fetch(urls.ACCESS_TOKEN_URL, { |
| 265 | method: "POST", |
| 266 | headers: { |
| 267 | Accept: "application/json", |
| 268 | "Content-Type": "application/json", |
| 269 | "User-Agent": `opencode/${InstallationVersion}`, |
| 270 | }, |
| 271 | body: JSON.stringify({ |
| 272 | client_id: CLIENT_ID, |
| 273 | device_code: deviceData.device_code, |
| 274 | grant_type: "urn:ietf:params:oauth:grant-type:device_code", |
| 275 | }), |
| 276 | }) |
| 277 | |
| 278 | if (!response.ok) return { type: "failed" as const } |
| 279 |
nothing calls this directly
no test coverage detected