@@ -20609,13 +20609,17 @@ async function discoverOAuthServerInfo(serverUrl, headers = {}) {
2060920609 wwwAuthenticateScope
2061020610 };
2061120611}
20612- async function finishOAuthAuthorization(finishAuth, authorizationCode, authTimeoutMs = 3e4) {
20612+ async function finishOAuthAuthorization(finishAuth, authorizationCode, authTimeoutMs = 3e4, authorizationDeadlineMs = Date.now() + authTimeoutMs) {
20613+ const remainingMs = authorizationDeadlineMs - Date.now();
20614+ if (remainingMs <= 0) {
20615+ throw new Error("OAuth authorization deadline expired before token exchange");
20616+ }
2061320617 let timeout;
2061420618 try {
2061520619 await Promise.race([
2061620620 finishAuth(authorizationCode),
2061720621 new Promise((_, reject) => {
20618- timeout = setTimeout(() => reject(new Error(`OAuth token exchange timed out after ${authTimeoutMs / 1e3} seconds`)), authTimeoutMs );
20622+ timeout = setTimeout(() => reject(new Error(`OAuth token exchange timed out after ${remainingMs / 1e3} seconds`)), remainingMs );
2061920623 })
2062020624 ]);
2062120625 } finally {
@@ -20724,11 +20728,17 @@ async function connectToRemoteServer(client, serverUrl, authProvider, headers, a
2072420728 }
2072520729 log("Authentication required. Waiting for authorization...");
2072620730 debugLog("Waiting for auth code from callback server");
20731+ const authorizationDeadlineMs = Date.now() + authTimeoutMs;
2072720732 const code = await waitForAuthCode();
2072820733 debugLog("Received auth code from callback server");
2072920734 try {
2073020735 log("Completing authorization...");
20731- await finishOAuthAuthorization((authorizationCode) => transport.finishAuth(authorizationCode), code, authTimeoutMs);
20736+ await finishOAuthAuthorization(
20737+ (authorizationCode) => transport.finishAuth(authorizationCode),
20738+ code,
20739+ authTimeoutMs,
20740+ authorizationDeadlineMs
20741+ );
2073220742 markAuthCompleted();
2073320743 debugLog("Authorization completed successfully");
2073420744 if (recursionReasons.has(REASON_AUTH_NEEDED)) {
0 commit comments