@omnicross/subscriptions 0.1.0 → 0.1.2
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/dist/chunk-IXGHVMZB.js +365 -0
- package/dist/chunk-TPW5Q25Y.cjs +365 -0
- package/dist/index.cjs +122 -627
- package/dist/index.d.cts +11 -677
- package/dist/index.d.ts +11 -677
- package/dist/index.js +17 -482
- package/dist/oauth.cjs +4 -390
- package/dist/oauth.d.cts +3 -4
- package/dist/oauth.d.ts +3 -4
- package/dist/oauth.js +5 -358
- package/package.json +2 -1
package/dist/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
};
|
|
1
|
+
import {
|
|
2
|
+
claude_exports,
|
|
3
|
+
codex_exports,
|
|
4
|
+
gemini_exports
|
|
5
|
+
} from "./chunk-IXGHVMZB.js";
|
|
6
6
|
|
|
7
7
|
// src/auth/OAuthBearerAuthStrategy.ts
|
|
8
8
|
var REFRESH_LEAD_MS = 5 * 6e4;
|
|
@@ -223,27 +223,11 @@ function getSubscriptionAccountService() {
|
|
|
223
223
|
return _moduleSingleton;
|
|
224
224
|
}
|
|
225
225
|
|
|
226
|
-
//
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
// ../core/src/transformer/transformers/GeminiCodeAssistTransformer.ts
|
|
233
|
-
var DEFAULT_CODE_ASSIST_ENDPOINT = "https://cloudcode-pa.googleapis.com";
|
|
234
|
-
var DEFAULT_CODE_ASSIST_API_VERSION = "v1internal";
|
|
235
|
-
function resolveCodeAssistEndpoint() {
|
|
236
|
-
return (process.env.CODE_ASSIST_ENDPOINT || DEFAULT_CODE_ASSIST_ENDPOINT).replace(/\/+$/, "");
|
|
237
|
-
}
|
|
238
|
-
function resolveCodeAssistApiVersion() {
|
|
239
|
-
return process.env.CODE_ASSIST_API_VERSION || DEFAULT_CODE_ASSIST_API_VERSION;
|
|
240
|
-
}
|
|
241
|
-
function buildCodeAssistUrl(stream) {
|
|
242
|
-
const base = resolveCodeAssistEndpoint();
|
|
243
|
-
const version = resolveCodeAssistApiVersion();
|
|
244
|
-
const method = stream ? "streamGenerateContent?alt=sse" : "generateContent";
|
|
245
|
-
return `${base}/${version}:${method}`;
|
|
246
|
-
}
|
|
226
|
+
// src/SubscriptionProviderRegistry.ts
|
|
227
|
+
import {
|
|
228
|
+
setSubscriptionRegistryForOutbound
|
|
229
|
+
} from "@omnicross/core/outbound-api/subscriptionRegistryPort";
|
|
230
|
+
import { buildCodeAssistUrl } from "@omnicross/core/transformer/transformers/GeminiCodeAssistTransformer";
|
|
247
231
|
|
|
248
232
|
// src/opencodego/CircuitBreaker.ts
|
|
249
233
|
var CircuitBreaker = class {
|
|
@@ -844,106 +828,10 @@ function getSubscriptionProviderRegistry() {
|
|
|
844
828
|
return _moduleSingleton2;
|
|
845
829
|
}
|
|
846
830
|
|
|
847
|
-
//
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
}
|
|
852
|
-
|
|
853
|
-
// ../core/src/provider-proxy/matchText.ts
|
|
854
|
-
var MATCH_TEXT_PER_MESSAGE_CAP = 8192;
|
|
855
|
-
var MATCH_TEXT_RECENT_MESSAGES = 6;
|
|
856
|
-
function flattenMatchText(value) {
|
|
857
|
-
if (typeof value === "string") return value;
|
|
858
|
-
if (Array.isArray(value)) {
|
|
859
|
-
const parts = [];
|
|
860
|
-
for (const item of value) {
|
|
861
|
-
const text = flattenMatchText(item);
|
|
862
|
-
if (text) parts.push(text);
|
|
863
|
-
}
|
|
864
|
-
return parts.join("\n");
|
|
865
|
-
}
|
|
866
|
-
if (value && typeof value === "object") {
|
|
867
|
-
const obj = value;
|
|
868
|
-
if (obj.type === "tool_result" && obj.content !== void 0) {
|
|
869
|
-
return flattenMatchText(obj.content);
|
|
870
|
-
}
|
|
871
|
-
if (typeof obj.text === "string") return obj.text;
|
|
872
|
-
}
|
|
873
|
-
return "";
|
|
874
|
-
}
|
|
875
|
-
function collectMatchText(anthropicBody) {
|
|
876
|
-
const messages = Array.isArray(anthropicBody.messages) ? anthropicBody.messages : [];
|
|
877
|
-
const slices = [];
|
|
878
|
-
const sys = flattenMatchText(anthropicBody.system).trim();
|
|
879
|
-
if (sys) slices.push(sys.slice(0, MATCH_TEXT_PER_MESSAGE_CAP));
|
|
880
|
-
const recent = [];
|
|
881
|
-
for (let i = messages.length - 1; i >= 0 && recent.length < MATCH_TEXT_RECENT_MESSAGES; i--) {
|
|
882
|
-
const message = messages[i];
|
|
883
|
-
if (!message || typeof message !== "object") continue;
|
|
884
|
-
const role = message.role;
|
|
885
|
-
if (role !== "user" && role !== "system") continue;
|
|
886
|
-
const text = flattenMatchText(message.content).trim();
|
|
887
|
-
if (text) recent.push(text.slice(0, MATCH_TEXT_PER_MESSAGE_CAP));
|
|
888
|
-
}
|
|
889
|
-
for (let i = recent.length - 1; i >= 0; i--) slices.push(recent[i]);
|
|
890
|
-
return slices;
|
|
891
|
-
}
|
|
892
|
-
|
|
893
|
-
// ../core/src/serializeError.ts
|
|
894
|
-
function serializeError(err) {
|
|
895
|
-
if (err == null) return "Unknown error (null)";
|
|
896
|
-
if (err instanceof Error) {
|
|
897
|
-
let msg = err.message || err.name || "Error";
|
|
898
|
-
if (err.cause) {
|
|
899
|
-
msg += ` [cause: ${serializeError(err.cause)}]`;
|
|
900
|
-
}
|
|
901
|
-
const anyErr = err;
|
|
902
|
-
if (anyErr.status != null) msg += ` (status: ${anyErr.status})`;
|
|
903
|
-
else if (anyErr.code != null) msg += ` (code: ${anyErr.code})`;
|
|
904
|
-
return msg;
|
|
905
|
-
}
|
|
906
|
-
if (typeof err === "string") return err || "Empty error string";
|
|
907
|
-
if (typeof err !== "object") return String(err);
|
|
908
|
-
const obj = err;
|
|
909
|
-
if (typeof obj.message === "string" && obj.message) {
|
|
910
|
-
let msg = obj.message;
|
|
911
|
-
if (obj.status != null) msg += ` (status: ${obj.status})`;
|
|
912
|
-
else if (obj.code != null) msg += ` (code: ${obj.code})`;
|
|
913
|
-
if (typeof obj.type === "string") msg += ` [type: ${obj.type}]`;
|
|
914
|
-
return msg;
|
|
915
|
-
}
|
|
916
|
-
if (typeof obj.error === "string" && obj.error) {
|
|
917
|
-
return obj.error;
|
|
918
|
-
}
|
|
919
|
-
if (obj.error && typeof obj.error === "object") {
|
|
920
|
-
const inner = obj.error;
|
|
921
|
-
if (typeof inner.message === "string" && inner.message) {
|
|
922
|
-
let msg = inner.message;
|
|
923
|
-
if (typeof inner.type === "string") msg += ` [type: ${inner.type}]`;
|
|
924
|
-
return msg;
|
|
925
|
-
}
|
|
926
|
-
}
|
|
927
|
-
try {
|
|
928
|
-
const json = JSON.stringify(err, getCircularReplacer(), 2);
|
|
929
|
-
if (json && json.length > 1e3) {
|
|
930
|
-
return json.slice(0, 1e3) + "... (truncated)";
|
|
931
|
-
}
|
|
932
|
-
return json || "Unserializable error";
|
|
933
|
-
} catch {
|
|
934
|
-
return `Unserializable error: ${Object.prototype.toString.call(err)}`;
|
|
935
|
-
}
|
|
936
|
-
}
|
|
937
|
-
function getCircularReplacer() {
|
|
938
|
-
const seen = /* @__PURE__ */ new WeakSet();
|
|
939
|
-
return (_key, value) => {
|
|
940
|
-
if (typeof value === "object" && value !== null) {
|
|
941
|
-
if (seen.has(value)) return "[Circular]";
|
|
942
|
-
seen.add(value);
|
|
943
|
-
}
|
|
944
|
-
return value;
|
|
945
|
-
};
|
|
946
|
-
}
|
|
831
|
+
// src/SubscriptionDispatcher.ts
|
|
832
|
+
import { getGeminiCodeAssistResolver } from "@omnicross/core/ports/gemini-code-assist-resolver";
|
|
833
|
+
import { collectMatchText } from "@omnicross/core/provider-proxy/matchText";
|
|
834
|
+
import { serializeError } from "@omnicross/core/serializeError";
|
|
947
835
|
|
|
948
836
|
// src/opencodego/token-count.ts
|
|
949
837
|
var cachedEncode = null;
|
|
@@ -1186,9 +1074,9 @@ var SubscriptionDispatcher = class {
|
|
|
1186
1074
|
const bearer = probe.Authorization ?? probe.authorization ?? "";
|
|
1187
1075
|
const accessToken = bearer.replace(/^Bearer\s+/i, "").trim();
|
|
1188
1076
|
if (!accessToken) return void 0;
|
|
1189
|
-
const
|
|
1190
|
-
if (!
|
|
1191
|
-
return
|
|
1077
|
+
const resolver = getGeminiCodeAssistResolver();
|
|
1078
|
+
if (!resolver) return void 0;
|
|
1079
|
+
return resolver.resolveProject(accessToken);
|
|
1192
1080
|
}
|
|
1193
1081
|
resolveTransformers(names) {
|
|
1194
1082
|
if (!names || names.length === 0) return [];
|
|
@@ -1272,359 +1160,6 @@ function stripAuthHeaders(headers) {
|
|
|
1272
1160
|
delete headers["x-goog-api-key"];
|
|
1273
1161
|
delete headers["X-Goog-Api-Key"];
|
|
1274
1162
|
}
|
|
1275
|
-
|
|
1276
|
-
// src/oauth/flows/claude.ts
|
|
1277
|
-
var claude_exports = {};
|
|
1278
|
-
__export(claude_exports, {
|
|
1279
|
-
exchangeCodeForTokens: () => exchangeCodeForTokens,
|
|
1280
|
-
exchangeSetupTokenCode: () => exchangeSetupTokenCode,
|
|
1281
|
-
generateAuthParams: () => generateAuthParams,
|
|
1282
|
-
generateSetupTokenParams: () => generateSetupTokenParams,
|
|
1283
|
-
refreshAccessToken: () => refreshAccessToken
|
|
1284
|
-
});
|
|
1285
|
-
import crypto from "crypto";
|
|
1286
|
-
|
|
1287
|
-
// src/oauth/fetchPort.ts
|
|
1288
|
-
function errorMessage(error, errorDescription) {
|
|
1289
|
-
if (errorDescription) return errorDescription;
|
|
1290
|
-
if (typeof error === "string") return error;
|
|
1291
|
-
if (error && typeof error === "object") {
|
|
1292
|
-
const e = error;
|
|
1293
|
-
if (typeof e.message === "string" && e.message) return e.message;
|
|
1294
|
-
if (typeof e.error_description === "string" && e.error_description) {
|
|
1295
|
-
return e.error_description;
|
|
1296
|
-
}
|
|
1297
|
-
return JSON.stringify(error);
|
|
1298
|
-
}
|
|
1299
|
-
return String(error);
|
|
1300
|
-
}
|
|
1301
|
-
async function postForm(fetchImpl, url, params, parseErrorMessage) {
|
|
1302
|
-
const response = await fetchImpl(url, {
|
|
1303
|
-
method: "POST",
|
|
1304
|
-
headers: { "Content-Type": "application/x-www-form-urlencoded" },
|
|
1305
|
-
body: params.toString()
|
|
1306
|
-
});
|
|
1307
|
-
const responseData = await response.text();
|
|
1308
|
-
let data;
|
|
1309
|
-
try {
|
|
1310
|
-
data = JSON.parse(responseData);
|
|
1311
|
-
} catch {
|
|
1312
|
-
throw new Error(parseErrorMessage);
|
|
1313
|
-
}
|
|
1314
|
-
if (data.error) {
|
|
1315
|
-
throw new Error(errorMessage(data.error, data.error_description));
|
|
1316
|
-
}
|
|
1317
|
-
return data;
|
|
1318
|
-
}
|
|
1319
|
-
async function postJson(fetchImpl, url, body, parseErrorMessage, extraHeaders = {}) {
|
|
1320
|
-
const response = await fetchImpl(url, {
|
|
1321
|
-
method: "POST",
|
|
1322
|
-
headers: { "Content-Type": "application/json", ...extraHeaders },
|
|
1323
|
-
body: JSON.stringify(body)
|
|
1324
|
-
});
|
|
1325
|
-
const responseData = await response.text();
|
|
1326
|
-
let data;
|
|
1327
|
-
try {
|
|
1328
|
-
data = JSON.parse(responseData);
|
|
1329
|
-
} catch {
|
|
1330
|
-
throw new Error(parseErrorMessage);
|
|
1331
|
-
}
|
|
1332
|
-
if (data.error) {
|
|
1333
|
-
throw new Error(errorMessage(data.error, data.error_description));
|
|
1334
|
-
}
|
|
1335
|
-
return data;
|
|
1336
|
-
}
|
|
1337
|
-
|
|
1338
|
-
// src/oauth/flows/claude.ts
|
|
1339
|
-
var CLAUDE_TOKEN_HEADERS = {
|
|
1340
|
-
"User-Agent": "claude-cli/1.0.56 (external, cli)",
|
|
1341
|
-
Accept: "application/json, text/plain, */*",
|
|
1342
|
-
"Accept-Language": "en-US,en;q=0.9",
|
|
1343
|
-
Referer: "https://claude.ai/",
|
|
1344
|
-
Origin: "https://claude.ai"
|
|
1345
|
-
};
|
|
1346
|
-
var CLAUDE_OAUTH_CONFIG = {
|
|
1347
|
-
clientId: "9d1c250a-e61b-44d9-88ed-5944d1962f5e",
|
|
1348
|
-
authorizationEndpoint: "https://claude.ai/oauth/authorize",
|
|
1349
|
-
// The token endpoint stays on console.anthropic.com (still the live value —
|
|
1350
|
-
// matches the official Claude Code CLI / claude-relay-service reference); only
|
|
1351
|
-
// the OAuth callback moved to platform.claude.com (2026). The redirect_uri MUST
|
|
1352
|
-
// match what the client is registered for AND match between authorize + token
|
|
1353
|
-
// exchange. Scopes mirror the live Claude Code authorize URL.
|
|
1354
|
-
tokenEndpoint: "https://console.anthropic.com/v1/oauth/token",
|
|
1355
|
-
redirectUri: "https://platform.claude.com/oauth/code/callback",
|
|
1356
|
-
scopes: [
|
|
1357
|
-
"org:create_api_key",
|
|
1358
|
-
"user:profile",
|
|
1359
|
-
"user:inference",
|
|
1360
|
-
"user:sessions:claude_code",
|
|
1361
|
-
"user:mcp_servers",
|
|
1362
|
-
"user:file_upload"
|
|
1363
|
-
]
|
|
1364
|
-
};
|
|
1365
|
-
var SETUP_TOKEN_CONFIG = {
|
|
1366
|
-
scopes: ["user:inference"]
|
|
1367
|
-
// Only inference permission, no API key creation
|
|
1368
|
-
};
|
|
1369
|
-
function generatePkce() {
|
|
1370
|
-
const codeVerifier = crypto.randomBytes(32).toString("base64url");
|
|
1371
|
-
const codeChallenge = crypto.createHash("sha256").update(codeVerifier).digest("base64url");
|
|
1372
|
-
const state = crypto.randomBytes(16).toString("hex");
|
|
1373
|
-
return { codeVerifier, codeChallenge, state };
|
|
1374
|
-
}
|
|
1375
|
-
function generateAuthParams() {
|
|
1376
|
-
const { codeVerifier, codeChallenge, state } = generatePkce();
|
|
1377
|
-
const params = new URLSearchParams({
|
|
1378
|
-
code: "true",
|
|
1379
|
-
client_id: CLAUDE_OAUTH_CONFIG.clientId,
|
|
1380
|
-
response_type: "code",
|
|
1381
|
-
redirect_uri: CLAUDE_OAUTH_CONFIG.redirectUri,
|
|
1382
|
-
scope: CLAUDE_OAUTH_CONFIG.scopes.join(" "),
|
|
1383
|
-
code_challenge: codeChallenge,
|
|
1384
|
-
code_challenge_method: "S256",
|
|
1385
|
-
state
|
|
1386
|
-
});
|
|
1387
|
-
const authUrl = `${CLAUDE_OAUTH_CONFIG.authorizationEndpoint}?${params.toString()}`;
|
|
1388
|
-
return { authUrl, codeVerifier, state };
|
|
1389
|
-
}
|
|
1390
|
-
function generateSetupTokenParams() {
|
|
1391
|
-
const { codeVerifier, codeChallenge, state } = generatePkce();
|
|
1392
|
-
const params = new URLSearchParams({
|
|
1393
|
-
code: "true",
|
|
1394
|
-
client_id: CLAUDE_OAUTH_CONFIG.clientId,
|
|
1395
|
-
response_type: "code",
|
|
1396
|
-
redirect_uri: CLAUDE_OAUTH_CONFIG.redirectUri,
|
|
1397
|
-
scope: SETUP_TOKEN_CONFIG.scopes.join(" "),
|
|
1398
|
-
code_challenge: codeChallenge,
|
|
1399
|
-
code_challenge_method: "S256",
|
|
1400
|
-
state
|
|
1401
|
-
});
|
|
1402
|
-
const authUrl = `${CLAUDE_OAUTH_CONFIG.authorizationEndpoint}?${params.toString()}`;
|
|
1403
|
-
return { authUrl, codeVerifier, state };
|
|
1404
|
-
}
|
|
1405
|
-
async function exchangeCodeForTokens(request, fetchImpl) {
|
|
1406
|
-
const { authorizationCode, codeVerifier, state } = request;
|
|
1407
|
-
const code = authorizationCode.split("#")[0]?.split("&")[0] ?? authorizationCode;
|
|
1408
|
-
const data = await postJson(
|
|
1409
|
-
fetchImpl,
|
|
1410
|
-
CLAUDE_OAUTH_CONFIG.tokenEndpoint,
|
|
1411
|
-
{
|
|
1412
|
-
grant_type: "authorization_code",
|
|
1413
|
-
client_id: CLAUDE_OAUTH_CONFIG.clientId,
|
|
1414
|
-
code,
|
|
1415
|
-
code_verifier: codeVerifier,
|
|
1416
|
-
redirect_uri: CLAUDE_OAUTH_CONFIG.redirectUri,
|
|
1417
|
-
state
|
|
1418
|
-
},
|
|
1419
|
-
"Failed to parse token response",
|
|
1420
|
-
CLAUDE_TOKEN_HEADERS
|
|
1421
|
-
);
|
|
1422
|
-
return {
|
|
1423
|
-
accessToken: data.access_token,
|
|
1424
|
-
// The authorization_code grant always returns a refresh_token; the original
|
|
1425
|
-
// helper read it from an untyped `data` and declared the field `string`.
|
|
1426
|
-
refreshToken: data.refresh_token,
|
|
1427
|
-
expiresIn: data.expires_in,
|
|
1428
|
-
scopes: data.scope?.split(" ") || CLAUDE_OAUTH_CONFIG.scopes
|
|
1429
|
-
};
|
|
1430
|
-
}
|
|
1431
|
-
async function exchangeSetupTokenCode(request, fetchImpl) {
|
|
1432
|
-
const { authorizationCode, codeVerifier, state } = request;
|
|
1433
|
-
const code = authorizationCode.split("#")[0]?.split("&")[0] ?? authorizationCode;
|
|
1434
|
-
const data = await postJson(
|
|
1435
|
-
fetchImpl,
|
|
1436
|
-
CLAUDE_OAUTH_CONFIG.tokenEndpoint,
|
|
1437
|
-
{
|
|
1438
|
-
grant_type: "authorization_code",
|
|
1439
|
-
client_id: CLAUDE_OAUTH_CONFIG.clientId,
|
|
1440
|
-
code,
|
|
1441
|
-
code_verifier: codeVerifier,
|
|
1442
|
-
redirect_uri: CLAUDE_OAUTH_CONFIG.redirectUri,
|
|
1443
|
-
state
|
|
1444
|
-
},
|
|
1445
|
-
"Failed to parse setup token response",
|
|
1446
|
-
CLAUDE_TOKEN_HEADERS
|
|
1447
|
-
);
|
|
1448
|
-
return {
|
|
1449
|
-
accessToken: data.access_token,
|
|
1450
|
-
expiresIn: data.expires_in,
|
|
1451
|
-
scopes: data.scope?.split(" ") || SETUP_TOKEN_CONFIG.scopes
|
|
1452
|
-
};
|
|
1453
|
-
}
|
|
1454
|
-
async function refreshAccessToken(refreshToken, fetchImpl) {
|
|
1455
|
-
const data = await postJson(
|
|
1456
|
-
fetchImpl,
|
|
1457
|
-
CLAUDE_OAUTH_CONFIG.tokenEndpoint,
|
|
1458
|
-
{
|
|
1459
|
-
grant_type: "refresh_token",
|
|
1460
|
-
client_id: CLAUDE_OAUTH_CONFIG.clientId,
|
|
1461
|
-
refresh_token: refreshToken
|
|
1462
|
-
},
|
|
1463
|
-
"Failed to parse refresh response",
|
|
1464
|
-
CLAUDE_TOKEN_HEADERS
|
|
1465
|
-
);
|
|
1466
|
-
return {
|
|
1467
|
-
accessToken: data.access_token,
|
|
1468
|
-
refreshToken: data.refresh_token || refreshToken,
|
|
1469
|
-
expiresIn: data.expires_in
|
|
1470
|
-
};
|
|
1471
|
-
}
|
|
1472
|
-
|
|
1473
|
-
// src/oauth/flows/codex.ts
|
|
1474
|
-
var codex_exports = {};
|
|
1475
|
-
__export(codex_exports, {
|
|
1476
|
-
exchangeCodeForTokens: () => exchangeCodeForTokens2,
|
|
1477
|
-
generateAuthParams: () => generateAuthParams2,
|
|
1478
|
-
refreshAccessToken: () => refreshAccessToken2
|
|
1479
|
-
});
|
|
1480
|
-
import crypto2 from "crypto";
|
|
1481
|
-
var CODEX_OAUTH_CONFIG = {
|
|
1482
|
-
clientId: "app_EMoamEEZ73f0CkXaXp7hrann",
|
|
1483
|
-
authorizationEndpoint: "https://auth.openai.com/oauth/authorize",
|
|
1484
|
-
tokenEndpoint: "https://auth.openai.com/oauth/token",
|
|
1485
|
-
redirectUri: "http://localhost:1455/auth/callback",
|
|
1486
|
-
scopes: ["openid", "profile", "email", "offline_access"]
|
|
1487
|
-
};
|
|
1488
|
-
function generateAuthParams2() {
|
|
1489
|
-
const codeVerifier = crypto2.randomBytes(64).toString("hex");
|
|
1490
|
-
const codeChallenge = crypto2.createHash("sha256").update(codeVerifier).digest("base64url");
|
|
1491
|
-
const state = crypto2.randomBytes(16).toString("hex");
|
|
1492
|
-
const params = new URLSearchParams({
|
|
1493
|
-
response_type: "code",
|
|
1494
|
-
client_id: CODEX_OAUTH_CONFIG.clientId,
|
|
1495
|
-
redirect_uri: CODEX_OAUTH_CONFIG.redirectUri,
|
|
1496
|
-
scope: CODEX_OAUTH_CONFIG.scopes.join(" "),
|
|
1497
|
-
code_challenge: codeChallenge,
|
|
1498
|
-
code_challenge_method: "S256",
|
|
1499
|
-
state
|
|
1500
|
-
});
|
|
1501
|
-
const authUrl = `${CODEX_OAUTH_CONFIG.authorizationEndpoint}?${params.toString()}`;
|
|
1502
|
-
return { authUrl, codeVerifier, state };
|
|
1503
|
-
}
|
|
1504
|
-
async function exchangeCodeForTokens2(request, fetchImpl) {
|
|
1505
|
-
const { authorizationCode, codeVerifier } = request;
|
|
1506
|
-
const params = new URLSearchParams({
|
|
1507
|
-
grant_type: "authorization_code",
|
|
1508
|
-
client_id: CODEX_OAUTH_CONFIG.clientId,
|
|
1509
|
-
code: authorizationCode,
|
|
1510
|
-
code_verifier: codeVerifier,
|
|
1511
|
-
redirect_uri: CODEX_OAUTH_CONFIG.redirectUri
|
|
1512
|
-
});
|
|
1513
|
-
const data = await postForm(
|
|
1514
|
-
fetchImpl,
|
|
1515
|
-
CODEX_OAUTH_CONFIG.tokenEndpoint,
|
|
1516
|
-
params,
|
|
1517
|
-
"Failed to parse token response"
|
|
1518
|
-
);
|
|
1519
|
-
return {
|
|
1520
|
-
accessToken: data.access_token,
|
|
1521
|
-
// authorization_code grant returns both; the original helper read them from
|
|
1522
|
-
// an untyped `data` and declared the fields `string`.
|
|
1523
|
-
refreshToken: data.refresh_token,
|
|
1524
|
-
idToken: data.id_token,
|
|
1525
|
-
expiresIn: data.expires_in
|
|
1526
|
-
};
|
|
1527
|
-
}
|
|
1528
|
-
async function refreshAccessToken2(refreshToken, fetchImpl) {
|
|
1529
|
-
const params = new URLSearchParams({
|
|
1530
|
-
grant_type: "refresh_token",
|
|
1531
|
-
client_id: CODEX_OAUTH_CONFIG.clientId,
|
|
1532
|
-
refresh_token: refreshToken,
|
|
1533
|
-
scope: "openid profile email"
|
|
1534
|
-
});
|
|
1535
|
-
const data = await postForm(
|
|
1536
|
-
fetchImpl,
|
|
1537
|
-
CODEX_OAUTH_CONFIG.tokenEndpoint,
|
|
1538
|
-
params,
|
|
1539
|
-
"Failed to parse refresh response"
|
|
1540
|
-
);
|
|
1541
|
-
return {
|
|
1542
|
-
accessToken: data.access_token,
|
|
1543
|
-
idToken: data.id_token,
|
|
1544
|
-
refreshToken: data.refresh_token || refreshToken,
|
|
1545
|
-
expiresIn: data.expires_in || 3600
|
|
1546
|
-
};
|
|
1547
|
-
}
|
|
1548
|
-
|
|
1549
|
-
// src/oauth/flows/gemini.ts
|
|
1550
|
-
var gemini_exports = {};
|
|
1551
|
-
__export(gemini_exports, {
|
|
1552
|
-
exchangeCodeForTokens: () => exchangeCodeForTokens3,
|
|
1553
|
-
generateAuthParams: () => generateAuthParams3,
|
|
1554
|
-
refreshAccessToken: () => refreshAccessToken3
|
|
1555
|
-
});
|
|
1556
|
-
import crypto3 from "crypto";
|
|
1557
|
-
var GEMINI_OAUTH_CONFIG = {
|
|
1558
|
-
clientId: "681255809395-oo8ft2oprdrnp9e3aqf6av3hmdib135j.apps.googleusercontent.com",
|
|
1559
|
-
// The Gemini CLI's *public* installed-app OAuth client secret (mirrors the
|
|
1560
|
-
// upstream CLI). Per Google's OAuth docs, native-app client secrets are not
|
|
1561
|
-
// treated as confidential — not a leaked key.
|
|
1562
|
-
clientSecret: "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",
|
|
1563
|
-
// allowlist-secret
|
|
1564
|
-
authorizationEndpoint: "https://accounts.google.com/o/oauth2/v2/auth",
|
|
1565
|
-
tokenEndpoint: "https://oauth2.googleapis.com/token",
|
|
1566
|
-
redirectUri: "urn:ietf:wg:oauth:2.0:oob",
|
|
1567
|
-
scopes: ["https://www.googleapis.com/auth/cloud-platform"]
|
|
1568
|
-
};
|
|
1569
|
-
function generateAuthParams3() {
|
|
1570
|
-
const codeVerifier = crypto3.randomBytes(32).toString("base64url");
|
|
1571
|
-
const codeChallenge = crypto3.createHash("sha256").update(codeVerifier).digest("base64url");
|
|
1572
|
-
const state = crypto3.randomBytes(16).toString("hex");
|
|
1573
|
-
const params = new URLSearchParams({
|
|
1574
|
-
client_id: GEMINI_OAUTH_CONFIG.clientId,
|
|
1575
|
-
redirect_uri: GEMINI_OAUTH_CONFIG.redirectUri,
|
|
1576
|
-
scope: GEMINI_OAUTH_CONFIG.scopes.join(" "),
|
|
1577
|
-
response_type: "code",
|
|
1578
|
-
code_challenge: codeChallenge,
|
|
1579
|
-
code_challenge_method: "S256",
|
|
1580
|
-
state,
|
|
1581
|
-
access_type: "offline",
|
|
1582
|
-
prompt: "consent"
|
|
1583
|
-
});
|
|
1584
|
-
const authUrl = `${GEMINI_OAUTH_CONFIG.authorizationEndpoint}?${params.toString()}`;
|
|
1585
|
-
return { authUrl, codeVerifier, state };
|
|
1586
|
-
}
|
|
1587
|
-
async function exchangeCodeForTokens3(authorizationCode, codeVerifier, fetchImpl) {
|
|
1588
|
-
const params = new URLSearchParams({
|
|
1589
|
-
grant_type: "authorization_code",
|
|
1590
|
-
client_id: GEMINI_OAUTH_CONFIG.clientId,
|
|
1591
|
-
client_secret: GEMINI_OAUTH_CONFIG.clientSecret,
|
|
1592
|
-
code: authorizationCode,
|
|
1593
|
-
code_verifier: codeVerifier,
|
|
1594
|
-
redirect_uri: GEMINI_OAUTH_CONFIG.redirectUri
|
|
1595
|
-
});
|
|
1596
|
-
const data = await postForm(
|
|
1597
|
-
fetchImpl,
|
|
1598
|
-
GEMINI_OAUTH_CONFIG.tokenEndpoint,
|
|
1599
|
-
params,
|
|
1600
|
-
"Failed to parse token response"
|
|
1601
|
-
);
|
|
1602
|
-
return {
|
|
1603
|
-
accessToken: data.access_token,
|
|
1604
|
-
// authorization_code grant returns a refresh_token; the original helper read
|
|
1605
|
-
// it from an untyped `data` and declared the field `string`.
|
|
1606
|
-
refreshToken: data.refresh_token,
|
|
1607
|
-
expiresIn: data.expires_in
|
|
1608
|
-
};
|
|
1609
|
-
}
|
|
1610
|
-
async function refreshAccessToken3(refreshToken, fetchImpl) {
|
|
1611
|
-
const params = new URLSearchParams({
|
|
1612
|
-
grant_type: "refresh_token",
|
|
1613
|
-
client_id: GEMINI_OAUTH_CONFIG.clientId,
|
|
1614
|
-
client_secret: GEMINI_OAUTH_CONFIG.clientSecret,
|
|
1615
|
-
refresh_token: refreshToken
|
|
1616
|
-
});
|
|
1617
|
-
const data = await postForm(
|
|
1618
|
-
fetchImpl,
|
|
1619
|
-
GEMINI_OAUTH_CONFIG.tokenEndpoint,
|
|
1620
|
-
params,
|
|
1621
|
-
"Failed to parse refresh response"
|
|
1622
|
-
);
|
|
1623
|
-
return {
|
|
1624
|
-
accessToken: data.access_token,
|
|
1625
|
-
expiresIn: data.expires_in
|
|
1626
|
-
};
|
|
1627
|
-
}
|
|
1628
1163
|
export {
|
|
1629
1164
|
SubscriptionAccountService,
|
|
1630
1165
|
SubscriptionDispatcher,
|