(input: {
readonly tokenEndpoint: string;
readonly clientId: string;
readonly refreshToken: string;
readonly headers?: Readonly<Record<string, string>>;
readonly serverOrigin?: string;
})
| 329 | * providers that issue refresh tokens reach here (WorkOS, which is form-encoded |
| 330 | * per RFC 8628); Better Auth's device flow issues no refresh token. */ |
| 331 | export const refreshDeviceTokens = async (input: { |
| 332 | readonly tokenEndpoint: string; |
| 333 | readonly clientId: string; |
| 334 | readonly refreshToken: string; |
| 335 | readonly headers?: Readonly<Record<string, string>>; |
| 336 | readonly serverOrigin?: string; |
| 337 | }): Promise<DeviceTokens> => { |
| 338 | const response = await post( |
| 339 | input.tokenEndpoint, |
| 340 | { |
| 341 | grant_type: "refresh_token", |
| 342 | refresh_token: input.refreshToken, |
| 343 | client_id: input.clientId, |
| 344 | }, |
| 345 | "form", |
| 346 | input, |
| 347 | ); |
| 348 | const body = await readJson(response); |
| 349 | if (!response.ok) { |
| 350 | throw new DeviceLoginError( |
| 351 | `Token refresh failed: ${asString(body.error_description) ?? asString(body.error) ?? `HTTP ${response.status}`}`, |
| 352 | ); |
| 353 | } |
| 354 | const accessToken = asString(body.access_token); |
| 355 | if (!accessToken) throw new DeviceLoginError("Refresh response was missing an access token."); |
| 356 | return { |
| 357 | accessToken, |
| 358 | refreshToken: asString(body.refresh_token) ?? input.refreshToken, |
| 359 | expiresAt: deriveExpiresAt({ accessToken, expiresIn: asNumber(body.expires_in) }), |
| 360 | }; |
| 361 | }; |
| 362 | |
| 363 | export type BrowserOpenCommand = readonly [command: string, args: ReadonlyArray<string>]; |
| 364 |
no test coverage detected