(refreshToken: string)
| 325 | } |
| 326 | |
| 327 | export async function refresh(refreshToken: string): Promise<TokenResponse> { |
| 328 | const url = `${Config.issuerBaseUrl}/oauth/token` |
| 329 | |
| 330 | const response = await fetch(url, { |
| 331 | method: "POST", |
| 332 | headers: { |
| 333 | "Content-Type": "application/x-www-form-urlencoded", |
| 334 | "User-Agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36", |
| 335 | }, |
| 336 | body: new URLSearchParams({ |
| 337 | grant_type: "refresh_token", |
| 338 | client_id: Config.clientId, |
| 339 | refresh_token: refreshToken, |
| 340 | }), |
| 341 | }) |
| 342 | |
| 343 | if (!response.ok) { |
| 344 | const errorText = await response.text() |
| 345 | throw new Error(`Failed to refresh token: ${response.status} - ${errorText}`) |
| 346 | } |
| 347 | |
| 348 | const tokens = (await response.json()) as TokenResponse |
| 349 | if (typeof tokens.expires_in !== "number") { |
| 350 | tokens.expires_in = 3600 |
| 351 | } |
| 352 | return tokens |
| 353 | } |
| 354 | |
| 355 | export async function get<T>(path: string): Promise<T> { |
| 356 | const auth = await Auth.get("codex") |
no test coverage detected