(refreshToken: string)
| 196 | * Refreshes an expired Codex access token. |
| 197 | */ |
| 198 | export async function refreshCodexToken(refreshToken: string): Promise<CodexTokens> { |
| 199 | const result = await postToTokenUrl( |
| 200 | new URLSearchParams({ |
| 201 | grant_type: 'refresh_token', |
| 202 | refresh_token: refreshToken, |
| 203 | client_id: CODEX_CLIENT_ID, |
| 204 | }), |
| 205 | ) |
| 206 | if (result.type !== 'success') { |
| 207 | throw new Error('Codex token refresh failed. Please re-login.') |
| 208 | } |
| 209 | const accountId = extractCodexAccountId(result.access) |
| 210 | if (!accountId) { |
| 211 | throw new Error('Failed to extract accountId from refreshed Codex token.') |
| 212 | } |
| 213 | return { |
| 214 | accessToken: result.access, |
| 215 | refreshToken: result.refresh, |
| 216 | expiresAt: result.expires, |
| 217 | accountId, |
| 218 | } |
| 219 | } |
| 220 | |
| 221 | // ── Local Callback Server ───────────────────────────────────────────────────── |
| 222 |
nothing calls this directly
no test coverage detected