(inputs = {})
| 461 | label: "Login with Snowflake (External Browser)", |
| 462 | prompts, |
| 463 | async authorize(inputs = {}) { |
| 464 | const account = normalizeAccount(inputs.account || "") |
| 465 | if (!account) throw new Error("Snowflake account is required") |
| 466 | |
| 467 | await startOAuthServer() |
| 468 | const pkce = await generatePKCE() |
| 469 | const state = generateRandomString(64) |
| 470 | const role = (inputs.role || "").trim() || undefined |
| 471 | const url = buildAuthorizeUrl(account, role, state, pkce) |
| 472 | const callbackPromise = waitForOAuthCallback(account, pkce, state) |
| 473 | await open(url).catch(() => undefined) |
| 474 | |
| 475 | return { |
| 476 | url, |
| 477 | instructions: |
| 478 | "Complete Snowflake sign-in in your browser. OpenCode will capture the OAuth callback and store the bearer token automatically.", |
| 479 | method: "auto" as const, |
| 480 | async callback() { |
| 481 | try { |
| 482 | const tokens = await callbackPromise |
| 483 | return { |
| 484 | type: "success" as const, |
| 485 | refresh: tokens.refresh_token!, |
| 486 | access: tokens.access_token, |
| 487 | expires: Date.now() + (tokens.expires_in ?? 600) * 1000, |
| 488 | accountId: account, |
| 489 | } |
| 490 | } catch { |
| 491 | return { type: "failed" as const } |
| 492 | } finally { |
| 493 | stopOAuthServer() |
| 494 | } |
| 495 | }, |
| 496 | } |
| 497 | }, |
| 498 | }, |
| 499 | { |
| 500 | type: "api", |
nothing calls this directly
no test coverage detected