MCPcopy Index your code
hub / github.com/anomalyco/opencode / waitForOAuthCallback

Function waitForOAuthCallback

packages/opencode/src/plugin/xai.ts:417–450  ·  view source on GitHub ↗
(pkce: PkceCodes, state: string)

Source from the content-addressed store, hash-verified

415}
416
417function waitForOAuthCallback(pkce: PkceCodes, state: string): Promise<TokenResponse> {
418 // A previous in-flight authorize() that the user abandoned (or that is
419 // being superseded by a fresh attempt) still owns `pendingOAuth`. Reject
420 // it eagerly so its caller stops waiting on a state value that can never
421 // match the next callback.
422 if (pendingOAuth) {
423 pendingOAuth.reject(new Error("Superseded by a newer xAI authorize request"))
424 pendingOAuth = undefined
425 }
426 return new Promise((resolve, reject) => {
427 const timeout = setTimeout(
428 () => {
429 if (pendingOAuth) {
430 pendingOAuth = undefined
431 reject(new Error("OAuth callback timeout - authorization took too long"))
432 }
433 },
434 5 * 60 * 1000,
435 )
436
437 pendingOAuth = {
438 pkce,
439 state,
440 resolve: (tokens) => {
441 clearTimeout(timeout)
442 resolve(tokens)
443 },
444 reject: (error) => {
445 clearTimeout(timeout)
446 reject(error)
447 },
448 }
449 })
450}
451
452interface RefreshResult {
453 access: string

Callers 1

XaiAuthPluginFunction · 0.70

Calls 3

resolveFunction · 0.70
rejectFunction · 0.50
rejectMethod · 0.45

Tested by

no test coverage detected