(refreshToken: string, options: XaiAuthPluginOptions = {})
| 165 | } |
| 166 | |
| 167 | async function refreshAccessToken(refreshToken: string, options: XaiAuthPluginOptions = {}): Promise<TokenResponse> { |
| 168 | const response = await fetch(options.tokenUrl ?? TOKEN_URL, { |
| 169 | method: "POST", |
| 170 | headers: authHeaders(), |
| 171 | body: new URLSearchParams({ |
| 172 | grant_type: "refresh_token", |
| 173 | refresh_token: refreshToken, |
| 174 | client_id: CLIENT_ID, |
| 175 | }).toString(), |
| 176 | }) |
| 177 | if (!response.ok) { |
| 178 | const detail = await response.text().catch(() => "") |
| 179 | throw new Error(`xAI token refresh failed (${response.status})${detail ? `: ${detail}` : ""}`) |
| 180 | } |
| 181 | return response.json() as Promise<TokenResponse> |
| 182 | } |
| 183 | |
| 184 | export interface DeviceCodeResponse { |
| 185 | device_code: string |
no test coverage detected