MCPcopy
hub / github.com/anomalyco/opencode / exchangeCodeForTokens

Function exchangeCodeForTokens

packages/opencode/src/plugin/xai.ts:144–165  ·  view source on GitHub ↗
(
  code: string,
  pkce: PkceCodes,
  options: XaiAuthPluginOptions = {},
)

Source from the content-addressed store, hash-verified

142}
143
144async function exchangeCodeForTokens(
145 code: string,
146 pkce: PkceCodes,
147 options: XaiAuthPluginOptions = {},
148): Promise<TokenResponse> {
149 const response = await fetch(options.tokenUrl ?? TOKEN_URL, {
150 method: "POST",
151 headers: authHeaders(),
152 body: new URLSearchParams({
153 grant_type: "authorization_code",
154 code,
155 redirect_uri: REDIRECT_URI,
156 client_id: CLIENT_ID,
157 code_verifier: pkce.verifier,
158 }).toString(),
159 })
160 if (!response.ok) {
161 const detail = await response.text().catch(() => "")
162 throw new Error(`xAI token exchange failed (${response.status})${detail ? `: ${detail}` : ""}`)
163 }
164 return response.json() as Promise<TokenResponse>
165}
166
167async function refreshAccessToken(refreshToken: string, options: XaiAuthPluginOptions = {}): Promise<TokenResponse> {
168 const response = await fetch(options.tokenUrl ?? TOKEN_URL, {

Callers 1

startOAuthServerFunction · 0.70

Calls 4

fetchFunction · 0.70
authHeadersFunction · 0.70
textMethod · 0.65
jsonMethod · 0.65

Tested by

no test coverage detected