@google/gemini-cli 0.64.0-preview.0 → 0.65.0-nightly.20261008.g44d764ee5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bundle/{chunk-2NQXIWQK.js → chunk-3E6LR7PD.js} +32 -4
- package/bundle/{chunk-EBP6K2WG.js → chunk-3HM2DUPL.js} +50 -18
- package/bundle/{chunk-HSZIYPL6.js → chunk-4YOFVKC3.js} +3 -3
- package/bundle/{chunk-KCCVXZ52.js → chunk-63N5Z55Y.js} +114 -69
- package/bundle/{chunk-UFQDAROY.js → chunk-7BGM6KG2.js} +1 -1
- package/bundle/{chunk-EDYPRCAA.js → chunk-7PODN7KW.js} +2 -2
- package/bundle/{chunk-ZQW7OGUO.js → chunk-ARJWMIGO.js} +628 -124
- package/bundle/{chunk-U76XPSKR.js → chunk-AUU7WOFW.js} +50 -18
- package/bundle/{chunk-SDWOC67Z.js → chunk-BA5YFKKS.js} +1 -1
- package/bundle/{chunk-UBGF6JU5.js → chunk-BIHX2DZB.js} +1 -1
- package/bundle/{chunk-HN74ORTP.js → chunk-EZGM7WCW.js} +32 -4
- package/bundle/{chunk-NX7TO2DU.js → chunk-G73R7Q4K.js} +1 -1
- package/bundle/{chunk-EFX5XL6M.js → chunk-HN32MQMG.js} +2 -2
- package/bundle/{chunk-VBVCLWLA.js → chunk-HRPULK65.js} +2 -2
- package/bundle/{chunk-A4TO2DY2.js → chunk-IL5DA7Y5.js} +8460 -14960
- package/bundle/{chunk-2VN53SWW.js → chunk-IUZHBNL5.js} +9 -8
- package/bundle/{chunk-EDVFNWRG.js → chunk-JPVUKQJ7.js} +1 -1
- package/bundle/{chunk-QUCRASYB.js → chunk-LGG27U7G.js} +1 -1
- package/bundle/{chunk-MLSLNORV.js → chunk-MV5ZEQKH.js} +3 -3
- package/bundle/chunk-PFU4B5QN.js +154 -0
- package/bundle/{chunk-ZPLFLZQA.js → chunk-PPUDMLP4.js} +38 -8
- package/bundle/{chunk-VJYKQD5D.js → chunk-Q2G3IFID.js} +3 -3
- package/bundle/chunk-Q6FM3IBA.js +512 -0
- package/bundle/chunk-RUV5VETL.js +17535 -0
- package/bundle/chunk-SQDLQBAY.js +118 -0
- package/bundle/chunk-UB5UMEXC.js +401700 -0
- package/bundle/{chunk-ZOHM7BPT.js → chunk-UCDMKAAW.js} +1 -1
- package/bundle/{chunk-Y2HXXBXI.js → chunk-XDI7ON7P.js} +1 -1
- package/bundle/{chunk-6OFXOGEG.js → chunk-XMBLOFHQ.js} +667 -128
- package/bundle/chunk-YMVWBWWO.js +1571 -0
- package/bundle/chunk-ZCMBTRVW.js +425 -0
- package/bundle/chunk-ZQB4PBVQ.js +103153 -0
- package/bundle/{cleanup-GGCB2LVD.js → cleanup-333PJ32W.js} +2 -2
- package/bundle/{cleanup-JRDG3OTL.js → cleanup-FAR6AR3H.js} +2 -2
- package/bundle/{cleanup-SSW6IXTR.js → cleanup-GL3Y6D27.js} +2 -2
- package/bundle/cleanup-JB3GTDPK.js +32 -0
- package/bundle/{core-IUIZE6JW.js → core-4FIJ3NBL.js} +13 -1
- package/bundle/{devtoolsService-3SADPKKB.js → devtoolsService-2WM4AKWJ.js} +2 -2
- package/bundle/{devtoolsService-XZCKFZP5.js → devtoolsService-3VV6G7M6.js} +2 -2
- package/bundle/{devtoolsService-MF6JKRUV.js → devtoolsService-4Q6IMJZW.js} +4 -3
- package/bundle/devtoolsService-MNAMTUTD.js +4359 -0
- package/bundle/{dist-7L3BRW6V.js → dist-B6O7SDYJ.js} +13 -1
- package/bundle/{core-6HRWFQZW.js → dist-BBUYPVDB.js} +13 -1
- package/bundle/dist-HG6AYV4Z.js +2264 -0
- package/bundle/docs/changelogs/index.md +14 -0
- package/bundle/docs/changelogs/latest.md +55 -34
- package/bundle/docs/changelogs/preview.md +59 -54
- package/bundle/docs/cli/telemetry.md +1 -0
- package/bundle/docs/reference/configuration.md +7 -0
- package/bundle/docs/tools/mcp-server.md +41 -12
- package/bundle/{gemini-JPMMQ3KA.js → gemini-3RQKEPRX.js} +41 -21
- package/bundle/{gemini-QOQNG5VY.js → gemini-O5W6WLU3.js} +241 -205
- package/bundle/gemini-PE5RKGLA.js +17954 -0
- package/bundle/{gemini-ZMMDUAQJ.js → gemini-TZNM5EXD.js} +41 -21
- package/bundle/gemini.js +7 -7
- package/bundle/{interactiveCli-UDWGRVJL.js → interactiveCli-EY52EA4C.js} +50 -32
- package/bundle/{interactiveCli-3I4TG5SK.js → interactiveCli-P4I2OMIO.js} +354 -317
- package/bundle/{interactiveCli-R3P4A3FC.js → interactiveCli-PGWKO5T6.js} +50 -32
- package/bundle/interactiveCli-T2TOLST3.js +34997 -0
- package/bundle/{liteRtServerManager-OVPUSK2T.js → liteRtServerManager-52LZHRIE.js} +4 -4
- package/bundle/{liteRtServerManager-RAV63AGE.js → liteRtServerManager-GG66IH7W.js} +4 -4
- package/bundle/{liteRtServerManager-4MWCEVVM.js → liteRtServerManager-TAPI266B.js} +4 -4
- package/bundle/liteRtServerManager-ZMK3WM5V.js +65 -0
- package/bundle/{oauth2-provider-FVTRRJZR.js → oauth2-provider-7PEUKPJH.js} +47 -9
- package/bundle/{oauth2-provider-XFP63FGJ.js → oauth2-provider-EU3BXPHB.js} +84 -80
- package/bundle/oauth2-provider-JB36DOZE.js +273 -0
- package/bundle/{oauth2-provider-EWOA64PR.js → oauth2-provider-W7KEN635.js} +51 -9
- package/bundle/{start-DJAIXPPY.js → start-2D4TOWA4.js} +6 -6
- package/bundle/{start-VQQ2Q5KT.js → start-G7MFP7R2.js} +6 -6
- package/bundle/{start-5O7TBK5L.js → start-VJAR6RFJ.js} +6 -6
- package/bundle/start-VWUPOWW5.js +18 -0
- package/package.json +1 -1
|
@@ -0,0 +1,273 @@
|
|
|
1
|
+
const require = (await import('node:module')).createRequire(import.meta.url); const __chunk_filename = (await import('node:url')).fileURLToPath(import.meta.url); const __chunk_dirname = (await import('node:path')).dirname(__chunk_filename);
|
|
2
|
+
import {
|
|
3
|
+
BaseA2AAuthProvider,
|
|
4
|
+
DefaultAgentCardResolver,
|
|
5
|
+
FatalCancellationError,
|
|
6
|
+
MCPOAuthTokenStorage,
|
|
7
|
+
Storage,
|
|
8
|
+
buildAuthorizationUrl,
|
|
9
|
+
coreEvents,
|
|
10
|
+
debugLogger,
|
|
11
|
+
exchangeCodeForToken,
|
|
12
|
+
generatePKCEParams,
|
|
13
|
+
getConsentForOauth,
|
|
14
|
+
getErrorMessage,
|
|
15
|
+
getPortFromUrl,
|
|
16
|
+
openBrowserSecurely,
|
|
17
|
+
refreshAccessToken,
|
|
18
|
+
startCallbackServer
|
|
19
|
+
} from "./chunk-ARJWMIGO.js";
|
|
20
|
+
import "./chunk-664ZODQF.js";
|
|
21
|
+
import "./chunk-IUUIT4SU.js";
|
|
22
|
+
import "./chunk-L6PII3GR.js";
|
|
23
|
+
import "./chunk-34MYV7JD.js";
|
|
24
|
+
|
|
25
|
+
// packages/core/dist/src/agents/auth-provider/oauth2-provider.js
|
|
26
|
+
var OAuth2AuthProvider = class extends BaseA2AAuthProvider {
|
|
27
|
+
config;
|
|
28
|
+
agentName;
|
|
29
|
+
agentCardUrl;
|
|
30
|
+
type = "oauth2";
|
|
31
|
+
tokenStorage;
|
|
32
|
+
cachedToken = null;
|
|
33
|
+
pendingAuthPromise = null;
|
|
34
|
+
/** Resolved OAuth URLs — may come from config or agent card. */
|
|
35
|
+
authorizationUrl;
|
|
36
|
+
tokenUrl;
|
|
37
|
+
scopes;
|
|
38
|
+
constructor(config, agentName, agentCard, agentCardUrl) {
|
|
39
|
+
super();
|
|
40
|
+
this.config = config;
|
|
41
|
+
this.agentName = agentName;
|
|
42
|
+
this.agentCardUrl = agentCardUrl;
|
|
43
|
+
this.tokenStorage = new MCPOAuthTokenStorage(Storage.getA2AOAuthTokensPath(), "gemini-cli-a2a");
|
|
44
|
+
this.authorizationUrl = config.authorization_url;
|
|
45
|
+
this.tokenUrl = config.token_url;
|
|
46
|
+
this.scopes = config.scopes;
|
|
47
|
+
this.mergeAgentCardDefaults(agentCard);
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Initialize the provider by loading any persisted token from storage.
|
|
51
|
+
* Also discovers OAuth URLs from the agent card if not yet resolved.
|
|
52
|
+
*/
|
|
53
|
+
async initialize() {
|
|
54
|
+
if ((!this.authorizationUrl || !this.tokenUrl) && this.agentCardUrl) {
|
|
55
|
+
await this.fetchAgentCardDefaults();
|
|
56
|
+
}
|
|
57
|
+
const credentials = await this.tokenStorage.getCredentials(this.agentName);
|
|
58
|
+
if (credentials && !this.tokenStorage.isTokenExpired(credentials.token)) {
|
|
59
|
+
this.cachedToken = credentials.token;
|
|
60
|
+
debugLogger.debug(`[OAuth2AuthProvider] Loaded valid cached token for "${this.agentName}"`);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Return an Authorization header with a valid Bearer token.
|
|
65
|
+
* Refreshes or triggers interactive auth as needed, deduplicating concurrent requests.
|
|
66
|
+
*/
|
|
67
|
+
async headers() {
|
|
68
|
+
if (this.cachedToken && !this.tokenStorage.isTokenExpired(this.cachedToken)) {
|
|
69
|
+
this.authRetryCount = 0;
|
|
70
|
+
return { Authorization: `Bearer ${this.cachedToken.accessToken}` };
|
|
71
|
+
}
|
|
72
|
+
if (!this.pendingAuthPromise) {
|
|
73
|
+
this.pendingAuthPromise = this.acquireToken().finally(() => {
|
|
74
|
+
this.pendingAuthPromise = null;
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
const token = await this.pendingAuthPromise;
|
|
78
|
+
this.authRetryCount = 0;
|
|
79
|
+
return { Authorization: `Bearer ${token.accessToken}` };
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Refresh an expired token or run interactive browser-based authentication.
|
|
83
|
+
*/
|
|
84
|
+
async acquireToken() {
|
|
85
|
+
if (this.cachedToken?.refreshToken && this.tokenUrl && this.config.client_id) {
|
|
86
|
+
try {
|
|
87
|
+
const refreshed = await refreshAccessToken({
|
|
88
|
+
clientId: this.config.client_id,
|
|
89
|
+
clientSecret: this.config.client_secret,
|
|
90
|
+
scopes: this.scopes
|
|
91
|
+
}, this.cachedToken.refreshToken, this.tokenUrl);
|
|
92
|
+
this.cachedToken = this.toOAuthToken(refreshed, this.cachedToken.refreshToken);
|
|
93
|
+
await this.persistToken();
|
|
94
|
+
return this.cachedToken;
|
|
95
|
+
} catch (error) {
|
|
96
|
+
debugLogger.debug(`[OAuth2AuthProvider] Refresh failed, falling back to interactive flow: ${getErrorMessage(error)}`);
|
|
97
|
+
this.cachedToken = null;
|
|
98
|
+
await this.tokenStorage.deleteCredentials(this.agentName);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
this.cachedToken = await this.authenticateInteractively();
|
|
102
|
+
return this.cachedToken;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Return the maximum number of consecutive authentication retries allowed.
|
|
106
|
+
*/
|
|
107
|
+
getMaxAuthRetries() {
|
|
108
|
+
return BaseA2AAuthProvider.MAX_AUTH_RETRIES;
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* On 401/403, clear the cached token and re-authenticate (up to MAX_AUTH_RETRIES).
|
|
112
|
+
*/
|
|
113
|
+
async shouldRetryWithHeaders(req, res) {
|
|
114
|
+
if (res.status !== 401 && res.status !== 403) {
|
|
115
|
+
this.authRetryCount = 0;
|
|
116
|
+
return void 0;
|
|
117
|
+
}
|
|
118
|
+
const reqHeaders = new Headers(req.headers);
|
|
119
|
+
const reqToken = reqHeaders.get("Authorization")?.split(" ")[1];
|
|
120
|
+
if (reqToken && (!this.cachedToken || reqToken !== this.cachedToken.accessToken)) {
|
|
121
|
+
debugLogger.debug("[OAuth2AuthProvider] Token already cleared or updated by another request, retrying with new token");
|
|
122
|
+
const retryCount = this.authRetryCount;
|
|
123
|
+
const headers2 = await this.headers();
|
|
124
|
+
this.authRetryCount = Math.max(this.authRetryCount, retryCount);
|
|
125
|
+
return headers2;
|
|
126
|
+
}
|
|
127
|
+
if (this.authRetryCount >= this.getMaxAuthRetries()) {
|
|
128
|
+
return void 0;
|
|
129
|
+
}
|
|
130
|
+
const nextRetryCount = this.authRetryCount + 1;
|
|
131
|
+
this.authRetryCount = nextRetryCount;
|
|
132
|
+
debugLogger.debug("[OAuth2AuthProvider] Auth failure, clearing token and re-authenticating");
|
|
133
|
+
this.cachedToken = null;
|
|
134
|
+
await this.tokenStorage.deleteCredentials(this.agentName);
|
|
135
|
+
const headers = await this.headers();
|
|
136
|
+
this.authRetryCount = nextRetryCount;
|
|
137
|
+
return headers;
|
|
138
|
+
}
|
|
139
|
+
// ---------------------------------------------------------------------------
|
|
140
|
+
// Private helpers
|
|
141
|
+
// ---------------------------------------------------------------------------
|
|
142
|
+
/**
|
|
143
|
+
* Merge authorization_url, token_url, and scopes from the agent card's
|
|
144
|
+
* `securitySchemes` when not already provided via user config.
|
|
145
|
+
*/
|
|
146
|
+
mergeAgentCardDefaults(agentCard) {
|
|
147
|
+
if (!agentCard?.securitySchemes)
|
|
148
|
+
return;
|
|
149
|
+
for (const scheme of Object.values(agentCard.securitySchemes)) {
|
|
150
|
+
if (scheme.type === "oauth2" && scheme.flows.authorizationCode) {
|
|
151
|
+
const flow = scheme.flows.authorizationCode;
|
|
152
|
+
this.authorizationUrl ??= flow.authorizationUrl;
|
|
153
|
+
this.tokenUrl ??= flow.tokenUrl;
|
|
154
|
+
this.scopes ??= Object.keys(flow.scopes);
|
|
155
|
+
break;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Fetch the agent card from `agentCardUrl` using `DefaultAgentCardResolver`
|
|
161
|
+
* (which normalizes proto-format cards) and extract OAuth2 URLs.
|
|
162
|
+
*/
|
|
163
|
+
async fetchAgentCardDefaults() {
|
|
164
|
+
if (!this.agentCardUrl)
|
|
165
|
+
return;
|
|
166
|
+
try {
|
|
167
|
+
debugLogger.debug(`[OAuth2AuthProvider] Fetching agent card from ${this.agentCardUrl}`);
|
|
168
|
+
const resolver = new DefaultAgentCardResolver();
|
|
169
|
+
const card = await resolver.resolve(this.agentCardUrl, "");
|
|
170
|
+
this.mergeAgentCardDefaults(card);
|
|
171
|
+
} catch (error) {
|
|
172
|
+
debugLogger.warn(`[OAuth2AuthProvider] Could not fetch agent card for OAuth URL discovery: ${getErrorMessage(error)}`);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Run a full OAuth 2.0 Authorization Code + PKCE flow through the browser.
|
|
177
|
+
*/
|
|
178
|
+
async authenticateInteractively() {
|
|
179
|
+
if (!this.config.client_id) {
|
|
180
|
+
throw new Error(`OAuth2 authentication for agent "${this.agentName}" requires a client_id. Add client_id to the auth config in your agent definition.`);
|
|
181
|
+
}
|
|
182
|
+
if (!this.authorizationUrl || !this.tokenUrl) {
|
|
183
|
+
throw new Error(`OAuth2 authentication for agent "${this.agentName}" requires authorization_url and token_url. Provide them in the auth config or ensure the agent card exposes an oauth2 security scheme.`);
|
|
184
|
+
}
|
|
185
|
+
const flowConfig = {
|
|
186
|
+
clientId: this.config.client_id,
|
|
187
|
+
clientSecret: this.config.client_secret,
|
|
188
|
+
authorizationUrl: this.authorizationUrl,
|
|
189
|
+
tokenUrl: this.tokenUrl,
|
|
190
|
+
scopes: this.scopes
|
|
191
|
+
};
|
|
192
|
+
const pkceParams = generatePKCEParams();
|
|
193
|
+
const preferredPort = getPortFromUrl(flowConfig.redirectUri);
|
|
194
|
+
const callbackServer = startCallbackServer(pkceParams.state, preferredPort);
|
|
195
|
+
const redirectPort = await callbackServer.port;
|
|
196
|
+
const authUrl = buildAuthorizationUrl(
|
|
197
|
+
flowConfig,
|
|
198
|
+
pkceParams,
|
|
199
|
+
redirectPort,
|
|
200
|
+
/* resource= */
|
|
201
|
+
void 0
|
|
202
|
+
);
|
|
203
|
+
const consent = await getConsentForOauth(`Authentication required for A2A agent: '${this.agentName}'.`);
|
|
204
|
+
if (!consent) {
|
|
205
|
+
const cancelError = new FatalCancellationError("Authentication cancelled by user.");
|
|
206
|
+
callbackServer.response.catch(() => {
|
|
207
|
+
});
|
|
208
|
+
callbackServer.cancel?.(cancelError);
|
|
209
|
+
throw cancelError;
|
|
210
|
+
}
|
|
211
|
+
coreEvents.emitFeedback("info", `\u2192 Opening your browser for OAuth sign-in...
|
|
212
|
+
|
|
213
|
+
If the browser does not open, copy and paste this URL into your browser:
|
|
214
|
+
${authUrl}
|
|
215
|
+
|
|
216
|
+
\u{1F4A1} TIP: Triple-click to select the entire URL, then copy and paste it into your browser.
|
|
217
|
+
\u26A0\uFE0F Make sure to copy the COMPLETE URL - it may wrap across multiple lines.`);
|
|
218
|
+
try {
|
|
219
|
+
await openBrowserSecurely(authUrl);
|
|
220
|
+
} catch (error) {
|
|
221
|
+
debugLogger.warn("Failed to open browser automatically:", getErrorMessage(error));
|
|
222
|
+
}
|
|
223
|
+
const { code } = await callbackServer.response;
|
|
224
|
+
debugLogger.debug("\u2713 Authorization code received, exchanging for tokens...");
|
|
225
|
+
const tokenResponse = await exchangeCodeForToken(
|
|
226
|
+
flowConfig,
|
|
227
|
+
code,
|
|
228
|
+
pkceParams.codeVerifier,
|
|
229
|
+
redirectPort,
|
|
230
|
+
/* resource= */
|
|
231
|
+
void 0
|
|
232
|
+
);
|
|
233
|
+
if (!tokenResponse.access_token) {
|
|
234
|
+
throw new Error("No access token received from token endpoint");
|
|
235
|
+
}
|
|
236
|
+
const token = this.toOAuthToken(tokenResponse);
|
|
237
|
+
this.cachedToken = token;
|
|
238
|
+
await this.persistToken();
|
|
239
|
+
debugLogger.debug("\u2713 OAuth2 authentication successful! Token saved.");
|
|
240
|
+
return token;
|
|
241
|
+
}
|
|
242
|
+
/**
|
|
243
|
+
* Convert an `OAuthTokenResponse` into the internal `OAuthToken` format.
|
|
244
|
+
*/
|
|
245
|
+
toOAuthToken(response, fallbackRefreshToken) {
|
|
246
|
+
const token = {
|
|
247
|
+
accessToken: response.access_token,
|
|
248
|
+
tokenType: response.token_type || "Bearer",
|
|
249
|
+
refreshToken: response.refresh_token || fallbackRefreshToken,
|
|
250
|
+
scope: response.scope
|
|
251
|
+
};
|
|
252
|
+
if (response.expires_in) {
|
|
253
|
+
token.expiresAt = Date.now() + response.expires_in * 1e3;
|
|
254
|
+
}
|
|
255
|
+
return token;
|
|
256
|
+
}
|
|
257
|
+
/**
|
|
258
|
+
* Persist the current cached token to disk.
|
|
259
|
+
*/
|
|
260
|
+
async persistToken() {
|
|
261
|
+
if (!this.cachedToken)
|
|
262
|
+
return;
|
|
263
|
+
await this.tokenStorage.saveToken(this.agentName, this.cachedToken, this.config.client_id, this.tokenUrl);
|
|
264
|
+
}
|
|
265
|
+
};
|
|
266
|
+
export {
|
|
267
|
+
OAuth2AuthProvider
|
|
268
|
+
};
|
|
269
|
+
/**
|
|
270
|
+
* @license
|
|
271
|
+
* Copyright 2026 Google LLC
|
|
272
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
273
|
+
*/
|
|
@@ -16,7 +16,7 @@ import {
|
|
|
16
16
|
openBrowserSecurely,
|
|
17
17
|
refreshAccessToken,
|
|
18
18
|
startCallbackServer
|
|
19
|
-
} from "./chunk-
|
|
19
|
+
} from "./chunk-XMBLOFHQ.js";
|
|
20
20
|
import "./chunk-664ZODQF.js";
|
|
21
21
|
import "./chunk-IUUIT4SU.js";
|
|
22
22
|
import "./chunk-L6PII3GR.js";
|
|
@@ -41,6 +41,7 @@ var OAuth2AuthProvider = class extends BaseA2AAuthProvider {
|
|
|
41
41
|
type = "oauth2";
|
|
42
42
|
tokenStorage;
|
|
43
43
|
cachedToken = null;
|
|
44
|
+
pendingAuthPromise = null;
|
|
44
45
|
/** Resolved OAuth URLs — may come from config or agent card. */
|
|
45
46
|
authorizationUrl;
|
|
46
47
|
tokenUrl;
|
|
@@ -63,12 +64,26 @@ var OAuth2AuthProvider = class extends BaseA2AAuthProvider {
|
|
|
63
64
|
}
|
|
64
65
|
/**
|
|
65
66
|
* Return an Authorization header with a valid Bearer token.
|
|
66
|
-
* Refreshes or triggers interactive auth as needed.
|
|
67
|
+
* Refreshes or triggers interactive auth as needed, deduplicating concurrent requests.
|
|
67
68
|
*/
|
|
68
69
|
async headers() {
|
|
69
70
|
if (this.cachedToken && !this.tokenStorage.isTokenExpired(this.cachedToken)) {
|
|
71
|
+
this.authRetryCount = 0;
|
|
70
72
|
return { Authorization: `Bearer ${this.cachedToken.accessToken}` };
|
|
71
73
|
}
|
|
74
|
+
if (!this.pendingAuthPromise) {
|
|
75
|
+
this.pendingAuthPromise = this.acquireToken().finally(() => {
|
|
76
|
+
this.pendingAuthPromise = null;
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
const token = await this.pendingAuthPromise;
|
|
80
|
+
this.authRetryCount = 0;
|
|
81
|
+
return { Authorization: `Bearer ${token.accessToken}` };
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Refresh an expired token or run interactive browser-based authentication.
|
|
85
|
+
*/
|
|
86
|
+
async acquireToken() {
|
|
72
87
|
if (this.cachedToken?.refreshToken && this.tokenUrl && this.config.client_id) {
|
|
73
88
|
try {
|
|
74
89
|
const refreshed = await refreshAccessToken(
|
|
@@ -85,35 +100,56 @@ var OAuth2AuthProvider = class extends BaseA2AAuthProvider {
|
|
|
85
100
|
this.cachedToken.refreshToken
|
|
86
101
|
);
|
|
87
102
|
await this.persistToken();
|
|
88
|
-
return
|
|
103
|
+
return this.cachedToken;
|
|
89
104
|
} catch (error) {
|
|
90
105
|
debugLogger.debug(
|
|
91
106
|
`[OAuth2AuthProvider] Refresh failed, falling back to interactive flow: ${getErrorMessage(error)}`
|
|
92
107
|
);
|
|
108
|
+
this.cachedToken = null;
|
|
93
109
|
await this.tokenStorage.deleteCredentials(this.agentName);
|
|
94
110
|
}
|
|
95
111
|
}
|
|
96
112
|
this.cachedToken = await this.authenticateInteractively();
|
|
97
|
-
return
|
|
113
|
+
return this.cachedToken;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Return the maximum number of consecutive authentication retries allowed.
|
|
117
|
+
*/
|
|
118
|
+
getMaxAuthRetries() {
|
|
119
|
+
return BaseA2AAuthProvider.MAX_AUTH_RETRIES;
|
|
98
120
|
}
|
|
99
121
|
/**
|
|
100
122
|
* On 401/403, clear the cached token and re-authenticate (up to MAX_AUTH_RETRIES).
|
|
101
123
|
*/
|
|
102
|
-
async shouldRetryWithHeaders(
|
|
124
|
+
async shouldRetryWithHeaders(req, res) {
|
|
103
125
|
if (res.status !== 401 && res.status !== 403) {
|
|
104
126
|
this.authRetryCount = 0;
|
|
105
127
|
return void 0;
|
|
106
128
|
}
|
|
107
|
-
|
|
129
|
+
const reqHeaders = new Headers(req.headers);
|
|
130
|
+
const reqToken = reqHeaders.get("Authorization")?.split(" ")[1];
|
|
131
|
+
if (reqToken && (!this.cachedToken || reqToken !== this.cachedToken.accessToken)) {
|
|
132
|
+
debugLogger.debug(
|
|
133
|
+
"[OAuth2AuthProvider] Token already cleared or updated by another request, retrying with new token"
|
|
134
|
+
);
|
|
135
|
+
const retryCount = this.authRetryCount;
|
|
136
|
+
const headers2 = await this.headers();
|
|
137
|
+
this.authRetryCount = Math.max(this.authRetryCount, retryCount);
|
|
138
|
+
return headers2;
|
|
139
|
+
}
|
|
140
|
+
if (this.authRetryCount >= this.getMaxAuthRetries()) {
|
|
108
141
|
return void 0;
|
|
109
142
|
}
|
|
110
|
-
this.authRetryCount
|
|
143
|
+
const nextRetryCount = this.authRetryCount + 1;
|
|
144
|
+
this.authRetryCount = nextRetryCount;
|
|
111
145
|
debugLogger.debug(
|
|
112
146
|
"[OAuth2AuthProvider] Auth failure, clearing token and re-authenticating"
|
|
113
147
|
);
|
|
114
148
|
this.cachedToken = null;
|
|
115
149
|
await this.tokenStorage.deleteCredentials(this.agentName);
|
|
116
|
-
|
|
150
|
+
const headers = await this.headers();
|
|
151
|
+
this.authRetryCount = nextRetryCount;
|
|
152
|
+
return headers;
|
|
117
153
|
}
|
|
118
154
|
// ---------------------------------------------------------------------------
|
|
119
155
|
// Private helpers
|
|
@@ -190,7 +226,13 @@ var OAuth2AuthProvider = class extends BaseA2AAuthProvider {
|
|
|
190
226
|
`Authentication required for A2A agent: '${this.agentName}'.`
|
|
191
227
|
);
|
|
192
228
|
if (!consent) {
|
|
193
|
-
|
|
229
|
+
const cancelError = new FatalCancellationError(
|
|
230
|
+
"Authentication cancelled by user."
|
|
231
|
+
);
|
|
232
|
+
callbackServer.response.catch(() => {
|
|
233
|
+
});
|
|
234
|
+
callbackServer.cancel?.(cancelError);
|
|
235
|
+
throw cancelError;
|
|
194
236
|
}
|
|
195
237
|
coreEvents.emitFeedback(
|
|
196
238
|
"info",
|
|
@@ -2,12 +2,12 @@ const require = (await import('node:module')).createRequire(import.meta.url); co
|
|
|
2
2
|
import {
|
|
3
3
|
startCommand,
|
|
4
4
|
startServer
|
|
5
|
-
} from "./chunk-
|
|
6
|
-
import "./chunk-
|
|
7
|
-
import "./chunk-
|
|
8
|
-
import "./chunk-
|
|
9
|
-
import "./chunk-
|
|
10
|
-
import "./chunk-
|
|
5
|
+
} from "./chunk-4YOFVKC3.js";
|
|
6
|
+
import "./chunk-YMVWBWWO.js";
|
|
7
|
+
import "./chunk-3E6LR7PD.js";
|
|
8
|
+
import "./chunk-XDI7ON7P.js";
|
|
9
|
+
import "./chunk-BIHX2DZB.js";
|
|
10
|
+
import "./chunk-XMBLOFHQ.js";
|
|
11
11
|
import "./chunk-664ZODQF.js";
|
|
12
12
|
import "./chunk-IUUIT4SU.js";
|
|
13
13
|
import "./chunk-L6PII3GR.js";
|
|
@@ -2,12 +2,12 @@ const require = (await import('node:module')).createRequire(import.meta.url); co
|
|
|
2
2
|
import {
|
|
3
3
|
startCommand,
|
|
4
4
|
startServer
|
|
5
|
-
} from "./chunk-
|
|
6
|
-
import "./chunk-
|
|
7
|
-
import "./chunk-
|
|
8
|
-
import "./chunk-
|
|
9
|
-
import "./chunk-
|
|
10
|
-
import "./chunk-
|
|
5
|
+
} from "./chunk-SQDLQBAY.js";
|
|
6
|
+
import "./chunk-JPVUKQJ7.js";
|
|
7
|
+
import "./chunk-EZGM7WCW.js";
|
|
8
|
+
import "./chunk-IUZHBNL5.js";
|
|
9
|
+
import "./chunk-BA5YFKKS.js";
|
|
10
|
+
import "./chunk-IL5DA7Y5.js";
|
|
11
11
|
import "./chunk-664ZODQF.js";
|
|
12
12
|
import "./chunk-IUUIT4SU.js";
|
|
13
13
|
import "./chunk-L6PII3GR.js";
|
|
@@ -2,12 +2,12 @@ const require = (await import('node:module')).createRequire(import.meta.url); co
|
|
|
2
2
|
import {
|
|
3
3
|
startCommand,
|
|
4
4
|
startServer
|
|
5
|
-
} from "./chunk-
|
|
6
|
-
import "./chunk-
|
|
7
|
-
import "./chunk-
|
|
8
|
-
import "./chunk-
|
|
9
|
-
import "./chunk-
|
|
10
|
-
import "./chunk-
|
|
5
|
+
} from "./chunk-Q2G3IFID.js";
|
|
6
|
+
import "./chunk-UCDMKAAW.js";
|
|
7
|
+
import "./chunk-RUV5VETL.js";
|
|
8
|
+
import "./chunk-Q6FM3IBA.js";
|
|
9
|
+
import "./chunk-7BGM6KG2.js";
|
|
10
|
+
import "./chunk-ARJWMIGO.js";
|
|
11
11
|
import "./chunk-664ZODQF.js";
|
|
12
12
|
import "./chunk-IUUIT4SU.js";
|
|
13
13
|
import "./chunk-L6PII3GR.js";
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
const require = (await import('node:module')).createRequire(import.meta.url); const __chunk_filename = (await import('node:url')).fileURLToPath(import.meta.url); const __chunk_dirname = (await import('node:path')).dirname(__chunk_filename);
|
|
2
|
+
import {
|
|
3
|
+
startCommand,
|
|
4
|
+
startServer
|
|
5
|
+
} from "./chunk-MV5ZEQKH.js";
|
|
6
|
+
import "./chunk-LGG27U7G.js";
|
|
7
|
+
import "./chunk-PPUDMLP4.js";
|
|
8
|
+
import "./chunk-G73R7Q4K.js";
|
|
9
|
+
import "./chunk-PFU4B5QN.js";
|
|
10
|
+
import "./chunk-UB5UMEXC.js";
|
|
11
|
+
import "./chunk-664ZODQF.js";
|
|
12
|
+
import "./chunk-IUUIT4SU.js";
|
|
13
|
+
import "./chunk-L6PII3GR.js";
|
|
14
|
+
import "./chunk-34MYV7JD.js";
|
|
15
|
+
export {
|
|
16
|
+
startCommand,
|
|
17
|
+
startServer
|
|
18
|
+
};
|