(mcpName: string)
| 487 | * Opens the browser and waits for callback. |
| 488 | */ |
| 489 | export async function authenticate(mcpName: string): Promise<Status> { |
| 490 | const { authorizationUrl } = await startAuth(mcpName) |
| 491 | |
| 492 | if (!authorizationUrl) { |
| 493 | // Already authenticated |
| 494 | const s = await state() |
| 495 | return s.status[mcpName] ?? { status: "connected" } |
| 496 | } |
| 497 | |
| 498 | // Extract state from authorization URL to use as callback key |
| 499 | // If no state parameter, use mcpName as fallback |
| 500 | const authUrl = new URL(authorizationUrl) |
| 501 | const oauthState = authUrl.searchParams.get("state") ?? mcpName |
| 502 | |
| 503 | // Open browser |
| 504 | log.info("opening browser for oauth", { mcpName, url: authorizationUrl, state: oauthState }) |
| 505 | await open(authorizationUrl) |
| 506 | |
| 507 | // Wait for callback using the OAuth state parameter (or mcpName as fallback) |
| 508 | const code = await McpOAuthCallback.waitForCallback(oauthState) |
| 509 | |
| 510 | // Finish auth |
| 511 | return finishAuth(mcpName, code) |
| 512 | } |
| 513 | |
| 514 | /** |
| 515 | * Complete OAuth authentication with the authorization code. |
nothing calls this directly
no test coverage detected