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

Function exchangeCodeForTokens

packages/opencode/src/plugin/openai/codex.ts:107–123  ·  view source on GitHub ↗
(code: string, redirectUri: string, pkce: PkceCodes)

Source from the content-addressed store, hash-verified

105}
106
107async function exchangeCodeForTokens(code: string, redirectUri: string, pkce: PkceCodes): Promise<TokenResponse> {
108 const response = await fetch(`${ISSUER}/oauth/token`, {
109 method: "POST",
110 headers: { "Content-Type": "application/x-www-form-urlencoded" },
111 body: new URLSearchParams({
112 grant_type: "authorization_code",
113 code,
114 redirect_uri: redirectUri,
115 client_id: CLIENT_ID,
116 code_verifier: pkce.verifier,
117 }).toString(),
118 })
119 if (!response.ok) {
120 throw new Error(`Token exchange failed: ${response.status}`)
121 }
122 return response.json()
123}
124
125async function refreshAccessToken(refreshToken: string, issuer = ISSUER): Promise<TokenResponse> {
126 const response = await fetch(`${issuer}/oauth/token`, {

Callers 1

startOAuthServerFunction · 0.70

Calls 2

fetchFunction · 0.70
jsonMethod · 0.65

Tested by

no test coverage detected