(
refreshToken: string,
clientId: string
)
| 621 | |
| 622 | // Refresh access token |
| 623 | async refreshAccessToken( |
| 624 | refreshToken: string, |
| 625 | clientId: string |
| 626 | ): Promise<OAuthTokens> { |
| 627 | const metadata = await this.getServerMetadata(); |
| 628 | |
| 629 | const params = new URLSearchParams({ |
| 630 | grant_type: 'refresh_token', |
| 631 | refresh_token: refreshToken, |
| 632 | client_id: clientId, |
| 633 | }); |
| 634 | |
| 635 | const response = await fetch(metadata.token_endpoint, { |
| 636 | method: 'POST', |
| 637 | headers: { 'Content-Type': 'application/x-www-form-urlencoded' }, |
| 638 | body: params.toString(), |
| 639 | }); |
| 640 | |
| 641 | if (!response.ok) { |
| 642 | throw new Error('Failed to refresh token'); |
| 643 | } |
| 644 | |
| 645 | const data = await response.json() as { |
| 646 | access_token: string; |
| 647 | refresh_token?: string; |
| 648 | expires_in?: number; |
| 649 | token_type?: string; |
| 650 | }; |
| 651 | |
| 652 | return { |
| 653 | accessToken: data.access_token, |
| 654 | refreshToken: data.refresh_token || refreshToken, |
| 655 | expiresAt: data.expires_in ? Date.now() + data.expires_in * 1000 : undefined, |
| 656 | tokenType: data.token_type || 'Bearer', |
| 657 | }; |
| 658 | } |
| 659 | |
| 660 | // Check if the MCP server requires OAuth |
| 661 | async checkAuthRequired(): Promise<boolean> { |
no test coverage detected