(refreshToken: string)
| 85 | } |
| 86 | |
| 87 | async function refreshAccessToken(refreshToken: string): Promise<TokenData> { |
| 88 | const response = await fetch(`${getBaseUrl()}/api/oauth/token`, { |
| 89 | method: "POST", |
| 90 | headers: { "Content-Type": "application/x-www-form-urlencoded" }, |
| 91 | body: new URLSearchParams({ |
| 92 | grant_type: "refresh_token", |
| 93 | client_id: CLI_CLIENT_ID, |
| 94 | refresh_token: refreshToken, |
| 95 | }).toString(), |
| 96 | }); |
| 97 | |
| 98 | if (!response.ok) { |
| 99 | const err = (await response.json().catch(() => ({}))) as TokenErrorResponse; |
| 100 | throw new Error(err.error_description || err.error || "Failed to refresh token"); |
| 101 | } |
| 102 | |
| 103 | return (await response.json()) as TokenData; |
| 104 | } |
| 105 | |
| 106 | /** |
| 107 | * Returns a valid access token, refreshing if expired. Returns null if no |
no test coverage detected