@omnicross/subscriptions 0.3.1 → 0.4.1
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-L77HJY6V.js +1109 -0
- package/dist/chunk-QKWL53TJ.cjs +1109 -0
- package/dist/index.cjs +88 -8
- package/dist/index.d.cts +52 -2
- package/dist/index.d.ts +52 -2
- package/dist/index.js +86 -6
- package/dist/oauth.cjs +8 -2
- package/dist/oauth.d.cts +294 -1
- package/dist/oauth.d.ts +294 -1
- package/dist/oauth.js +7 -1
- package/package.json +3 -3
- package/dist/chunk-B2LHAP4F.cjs +0 -570
- package/dist/chunk-ZB3GA2Y2.js +0 -570
package/dist/chunk-B2LHAP4F.cjs
DELETED
|
@@ -1,570 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
2
|
-
|
|
3
|
-
var _chunk75ZPJI57cjs = require('./chunk-75ZPJI57.cjs');
|
|
4
|
-
|
|
5
|
-
// src/oauth/flows/kimi.ts
|
|
6
|
-
var kimi_exports = {};
|
|
7
|
-
_chunk75ZPJI57cjs.__export.call(void 0, kimi_exports, {
|
|
8
|
-
KIMI_CLI_VERSION: () => KIMI_CLI_VERSION,
|
|
9
|
-
KIMI_OAUTH_CONFIG: () => KIMI_OAUTH_CONFIG,
|
|
10
|
-
awaitDeviceToken: () => awaitDeviceToken,
|
|
11
|
-
generateKimiDeviceId: () => generateKimiDeviceId,
|
|
12
|
-
kimiAccountIdFromAccessToken: () => kimiAccountIdFromAccessToken,
|
|
13
|
-
kimiFingerprintHeaders: () => kimiFingerprintHeaders,
|
|
14
|
-
pollDeviceToken: () => pollDeviceToken,
|
|
15
|
-
refreshAccessToken: () => refreshAccessToken,
|
|
16
|
-
requestDeviceAuthorization: () => requestDeviceAuthorization
|
|
17
|
-
});
|
|
18
|
-
var _crypto = require('crypto'); var _crypto2 = _interopRequireDefault(_crypto);
|
|
19
|
-
var _os = require('os'); var os = _interopRequireWildcard(_os);
|
|
20
|
-
var KIMI_OAUTH_CONFIG = {
|
|
21
|
-
clientId: "17e5f671-d194-4dfb-9706-5516cb48c098",
|
|
22
|
-
deviceAuthorizationEndpoint: "https://auth.kimi.com/api/oauth/device_authorization",
|
|
23
|
-
tokenEndpoint: "https://auth.kimi.com/api/oauth/token"
|
|
24
|
-
};
|
|
25
|
-
var KIMI_CLI_VERSION = _nullishCoalesce(process.env["KIMI_CLI_VERSION"], () => ( "1.0.0"));
|
|
26
|
-
function sanitizeHeaderValue(value, fallback = "") {
|
|
27
|
-
const sanitized = value.replace(/[^\x20-\x7E]/g, "").trim();
|
|
28
|
-
return sanitized || fallback;
|
|
29
|
-
}
|
|
30
|
-
function deviceModel() {
|
|
31
|
-
const platform2 = os.platform();
|
|
32
|
-
const label = platform2 === "darwin" ? "macOS" : platform2 === "win32" ? "Windows" : platform2 === "linux" ? "Linux" : platform2;
|
|
33
|
-
return [label, os.release(), os.arch()].filter(Boolean).join(" ").trim();
|
|
34
|
-
}
|
|
35
|
-
function kimiFingerprintHeaders(deviceId) {
|
|
36
|
-
return {
|
|
37
|
-
"User-Agent": `KimiCLI/${KIMI_CLI_VERSION}`,
|
|
38
|
-
"X-Msh-Platform": "kimi_cli",
|
|
39
|
-
"X-Msh-Version": KIMI_CLI_VERSION,
|
|
40
|
-
"X-Msh-Device-Name": sanitizeHeaderValue(os.hostname(), "unknown"),
|
|
41
|
-
"X-Msh-Device-Model": sanitizeHeaderValue(deviceModel(), "unknown"),
|
|
42
|
-
"X-Msh-Os-Version": sanitizeHeaderValue(os.version(), "unknown"),
|
|
43
|
-
...deviceId ? { "X-Msh-Device-Id": sanitizeHeaderValue(deviceId) } : {}
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
|
-
function generateKimiDeviceId() {
|
|
47
|
-
return _crypto2.default.randomUUID().replace(/-/g, "");
|
|
48
|
-
}
|
|
49
|
-
async function postFormRaw(fetchImpl, url, params, headers, timeoutMs = 3e4) {
|
|
50
|
-
const controller = new AbortController();
|
|
51
|
-
const timer = setTimeout(() => controller.abort(), timeoutMs);
|
|
52
|
-
let response;
|
|
53
|
-
try {
|
|
54
|
-
response = await fetchImpl(url, {
|
|
55
|
-
method: "POST",
|
|
56
|
-
headers: { "Content-Type": "application/x-www-form-urlencoded", Accept: "application/json", ...headers },
|
|
57
|
-
body: params.toString(),
|
|
58
|
-
signal: controller.signal
|
|
59
|
-
});
|
|
60
|
-
} catch (error) {
|
|
61
|
-
if (controller.signal.aborted) throw new Error("token endpoint timed out");
|
|
62
|
-
throw error;
|
|
63
|
-
} finally {
|
|
64
|
-
clearTimeout(timer);
|
|
65
|
-
}
|
|
66
|
-
const text = await response.text();
|
|
67
|
-
let body;
|
|
68
|
-
try {
|
|
69
|
-
const parsed = JSON.parse(text);
|
|
70
|
-
body = parsed && typeof parsed === "object" && !Array.isArray(parsed) ? parsed : {};
|
|
71
|
-
} catch (e2) {
|
|
72
|
-
body = {};
|
|
73
|
-
}
|
|
74
|
-
return { status: response.status, body };
|
|
75
|
-
}
|
|
76
|
-
async function requestDeviceAuthorization(fetchImpl, fingerprint) {
|
|
77
|
-
const { status, body } = await postFormRaw(
|
|
78
|
-
fetchImpl,
|
|
79
|
-
KIMI_OAUTH_CONFIG.deviceAuthorizationEndpoint,
|
|
80
|
-
new URLSearchParams({ client_id: KIMI_OAUTH_CONFIG.clientId }),
|
|
81
|
-
_nullishCoalesce(fingerprint, () => ( {}))
|
|
82
|
-
);
|
|
83
|
-
const userCode = typeof body["user_code"] === "string" ? body["user_code"] : void 0;
|
|
84
|
-
const deviceCode = typeof body["device_code"] === "string" ? body["device_code"] : void 0;
|
|
85
|
-
const verificationUri = typeof body["verification_uri"] === "string" ? body["verification_uri"] : void 0;
|
|
86
|
-
if (status >= 400 || !userCode || !deviceCode || !verificationUri) {
|
|
87
|
-
const message = typeof body["error_description"] === "string" ? body["error_description"] : typeof body["msg"] === "string" ? body["msg"] : `device authorization failed (HTTP ${status})`;
|
|
88
|
-
throw new Error(message);
|
|
89
|
-
}
|
|
90
|
-
return {
|
|
91
|
-
userCode,
|
|
92
|
-
deviceCode,
|
|
93
|
-
verificationUri,
|
|
94
|
-
...typeof body["verification_uri_complete"] === "string" ? { verificationUriComplete: body["verification_uri_complete"] } : {},
|
|
95
|
-
...typeof body["interval"] === "number" ? { interval: body["interval"] } : {},
|
|
96
|
-
...typeof body["expires_in"] === "number" ? { expiresIn: body["expires_in"] } : {}
|
|
97
|
-
};
|
|
98
|
-
}
|
|
99
|
-
async function pollDeviceToken(deviceCode, fetchImpl, fingerprint) {
|
|
100
|
-
const { status, body } = await postFormRaw(
|
|
101
|
-
fetchImpl,
|
|
102
|
-
KIMI_OAUTH_CONFIG.tokenEndpoint,
|
|
103
|
-
new URLSearchParams({
|
|
104
|
-
grant_type: "urn:ietf:params:oauth:grant-type:device_code",
|
|
105
|
-
client_id: KIMI_OAUTH_CONFIG.clientId,
|
|
106
|
-
device_code: deviceCode
|
|
107
|
-
}),
|
|
108
|
-
_nullishCoalesce(fingerprint, () => ( {}))
|
|
109
|
-
);
|
|
110
|
-
const accessToken = typeof body["access_token"] === "string" ? body["access_token"] : void 0;
|
|
111
|
-
const refreshToken = typeof body["refresh_token"] === "string" ? body["refresh_token"] : void 0;
|
|
112
|
-
if (accessToken && refreshToken) {
|
|
113
|
-
const expiresIn = typeof body["expires_in"] === "number" && body["expires_in"] > 0 ? body["expires_in"] : 3600;
|
|
114
|
-
return { state: "done", accessToken, refreshToken, expiresIn };
|
|
115
|
-
}
|
|
116
|
-
const error = typeof body["error"] === "string" ? body["error"] : void 0;
|
|
117
|
-
if (error === "authorization_pending") return { state: "pending" };
|
|
118
|
-
if (error === "slow_down") return { state: "pending", intervalSeconds: 5 };
|
|
119
|
-
if (status < 400 && !error) return { state: "pending" };
|
|
120
|
-
const message = typeof body["error_description"] === "string" && body["error_description"] ? body["error_description"] : _nullishCoalesce(error, () => ( `device token poll failed (HTTP ${status})`));
|
|
121
|
-
return { state: "failed", message };
|
|
122
|
-
}
|
|
123
|
-
async function awaitDeviceToken(authorization, fetchImpl, options = {}) {
|
|
124
|
-
const sleep = _nullishCoalesce(options.sleep, () => ( ((ms) => new Promise((resolve) => setTimeout(resolve, ms)))));
|
|
125
|
-
const deadline = Date.now() + (_nullishCoalesce(options.deadlineMs, () => ( 15 * 6e4)));
|
|
126
|
-
const baseIntervalMs = _nullishCoalesce(options.intervalMs, () => ( (_nullishCoalesce(authorization.interval, () => ( 5))) * 1e3));
|
|
127
|
-
let intervalMs = Math.max(1e3, baseIntervalMs);
|
|
128
|
-
for (; ; ) {
|
|
129
|
-
const result = await pollDeviceToken(authorization.deviceCode, fetchImpl, options.fingerprint);
|
|
130
|
-
if (result.state === "done") return result;
|
|
131
|
-
if (result.state === "failed") throw new Error(result.message);
|
|
132
|
-
if (result.state === "pending" && result.intervalSeconds) intervalMs += result.intervalSeconds * 1e3;
|
|
133
|
-
_optionalChain([options, 'access', _ => _.onPending, 'optionalCall', _2 => _2()]);
|
|
134
|
-
if (Date.now() + intervalMs > deadline) throw new Error("device authorization timed out");
|
|
135
|
-
await sleep(intervalMs);
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
async function refreshAccessToken(refreshToken, fetchImpl, fingerprint) {
|
|
139
|
-
const { status, body } = await postFormRaw(
|
|
140
|
-
fetchImpl,
|
|
141
|
-
KIMI_OAUTH_CONFIG.tokenEndpoint,
|
|
142
|
-
new URLSearchParams({
|
|
143
|
-
grant_type: "refresh_token",
|
|
144
|
-
client_id: KIMI_OAUTH_CONFIG.clientId,
|
|
145
|
-
refresh_token: refreshToken
|
|
146
|
-
}),
|
|
147
|
-
_nullishCoalesce(fingerprint, () => ( {}))
|
|
148
|
-
);
|
|
149
|
-
const accessToken = typeof body["access_token"] === "string" ? body["access_token"] : void 0;
|
|
150
|
-
if (status >= 400 || !accessToken) {
|
|
151
|
-
const message = typeof body["error_description"] === "string" && body["error_description"] ? body["error_description"] : typeof body["error"] === "string" ? body["error"] : `refresh failed (HTTP ${status})`;
|
|
152
|
-
throw new Error(message);
|
|
153
|
-
}
|
|
154
|
-
return {
|
|
155
|
-
accessToken,
|
|
156
|
-
// Kimi rotates the refresh token; keep the old one when the response omits it.
|
|
157
|
-
refreshToken: typeof body["refresh_token"] === "string" && body["refresh_token"] ? body["refresh_token"] : refreshToken,
|
|
158
|
-
expiresIn: typeof body["expires_in"] === "number" && body["expires_in"] > 0 ? body["expires_in"] : 3600
|
|
159
|
-
};
|
|
160
|
-
}
|
|
161
|
-
function kimiAccountIdFromAccessToken(accessToken) {
|
|
162
|
-
const parts = accessToken.split(".");
|
|
163
|
-
if (parts.length !== 3) return void 0;
|
|
164
|
-
try {
|
|
165
|
-
const json = Buffer.from(parts[1], "base64url").toString("utf8");
|
|
166
|
-
const claims = JSON.parse(json);
|
|
167
|
-
if (!claims || typeof claims !== "object" || Array.isArray(claims)) return void 0;
|
|
168
|
-
const record = claims;
|
|
169
|
-
for (const key of ["user_id", "sub"]) {
|
|
170
|
-
const value = record[key];
|
|
171
|
-
if (typeof value === "string" && value.trim()) return value.trim();
|
|
172
|
-
}
|
|
173
|
-
return void 0;
|
|
174
|
-
} catch (e3) {
|
|
175
|
-
return void 0;
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
// src/oauth/flows/claude.ts
|
|
180
|
-
var claude_exports = {};
|
|
181
|
-
_chunk75ZPJI57cjs.__export.call(void 0, claude_exports, {
|
|
182
|
-
exchangeCodeForTokens: () => exchangeCodeForTokens,
|
|
183
|
-
exchangeSetupTokenCode: () => exchangeSetupTokenCode,
|
|
184
|
-
generateAuthParams: () => generateAuthParams,
|
|
185
|
-
generateSetupTokenParams: () => generateSetupTokenParams,
|
|
186
|
-
refreshAccessToken: () => refreshAccessToken2
|
|
187
|
-
});
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
// src/oauth/fetchPort.ts
|
|
191
|
-
function errorMessage(error, errorDescription) {
|
|
192
|
-
if (errorDescription) return errorDescription;
|
|
193
|
-
if (typeof error === "string") return error;
|
|
194
|
-
if (error && typeof error === "object") {
|
|
195
|
-
const e = error;
|
|
196
|
-
if (typeof e.message === "string" && e.message) return e.message;
|
|
197
|
-
if (typeof e.error_description === "string" && e.error_description) {
|
|
198
|
-
return e.error_description;
|
|
199
|
-
}
|
|
200
|
-
return JSON.stringify(error);
|
|
201
|
-
}
|
|
202
|
-
return String(error);
|
|
203
|
-
}
|
|
204
|
-
function withStatus(message, response) {
|
|
205
|
-
return response.ok ? message : `${message} (HTTP ${response.status})`;
|
|
206
|
-
}
|
|
207
|
-
var DEFAULT_TOKEN_TIMEOUT_MS = 3e4;
|
|
208
|
-
async function fetchWithTimeout(fetchImpl, url, init, timeoutMs) {
|
|
209
|
-
const controller = new AbortController();
|
|
210
|
-
const timer = setTimeout(() => controller.abort(), timeoutMs);
|
|
211
|
-
try {
|
|
212
|
-
return await fetchImpl(url, { ...init, signal: controller.signal });
|
|
213
|
-
} catch (e) {
|
|
214
|
-
if (controller.signal.aborted) {
|
|
215
|
-
throw new Error(`token endpoint timed out after ${Math.round(timeoutMs / 1e3)}s`);
|
|
216
|
-
}
|
|
217
|
-
throw e;
|
|
218
|
-
} finally {
|
|
219
|
-
clearTimeout(timer);
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
async function postForm(fetchImpl, url, params, parseErrorMessage, timeoutMs = DEFAULT_TOKEN_TIMEOUT_MS) {
|
|
223
|
-
const response = await fetchWithTimeout(
|
|
224
|
-
fetchImpl,
|
|
225
|
-
url,
|
|
226
|
-
{
|
|
227
|
-
method: "POST",
|
|
228
|
-
headers: { "Content-Type": "application/x-www-form-urlencoded" },
|
|
229
|
-
body: params.toString()
|
|
230
|
-
},
|
|
231
|
-
timeoutMs
|
|
232
|
-
);
|
|
233
|
-
const responseData = await response.text();
|
|
234
|
-
let data;
|
|
235
|
-
try {
|
|
236
|
-
data = JSON.parse(responseData);
|
|
237
|
-
} catch (e4) {
|
|
238
|
-
throw new Error(withStatus(parseErrorMessage, response));
|
|
239
|
-
}
|
|
240
|
-
if (data.error) {
|
|
241
|
-
throw new Error(withStatus(errorMessage(data.error, data.error_description), response));
|
|
242
|
-
}
|
|
243
|
-
return data;
|
|
244
|
-
}
|
|
245
|
-
async function postJson(fetchImpl, url, body, parseErrorMessage, extraHeaders = {}, timeoutMs = DEFAULT_TOKEN_TIMEOUT_MS) {
|
|
246
|
-
const response = await fetchWithTimeout(
|
|
247
|
-
fetchImpl,
|
|
248
|
-
url,
|
|
249
|
-
{
|
|
250
|
-
method: "POST",
|
|
251
|
-
headers: { "Content-Type": "application/json", ...extraHeaders },
|
|
252
|
-
body: JSON.stringify(body)
|
|
253
|
-
},
|
|
254
|
-
timeoutMs
|
|
255
|
-
);
|
|
256
|
-
const responseData = await response.text();
|
|
257
|
-
let data;
|
|
258
|
-
try {
|
|
259
|
-
data = JSON.parse(responseData);
|
|
260
|
-
} catch (e5) {
|
|
261
|
-
throw new Error(withStatus(parseErrorMessage, response));
|
|
262
|
-
}
|
|
263
|
-
if (data.error) {
|
|
264
|
-
throw new Error(withStatus(errorMessage(data.error, data.error_description), response));
|
|
265
|
-
}
|
|
266
|
-
if (!response.ok) {
|
|
267
|
-
throw new Error(withStatus("token endpoint rejected the request", response));
|
|
268
|
-
}
|
|
269
|
-
return data;
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
// src/oauth/flows/claude.ts
|
|
273
|
-
var CLAUDE_TOKEN_HEADERS = {
|
|
274
|
-
"User-Agent": "claude-cli/1.0.56 (external, cli)",
|
|
275
|
-
Accept: "application/json, text/plain, */*",
|
|
276
|
-
"Accept-Language": "en-US,en;q=0.9",
|
|
277
|
-
Referer: "https://claude.ai/",
|
|
278
|
-
Origin: "https://claude.ai"
|
|
279
|
-
};
|
|
280
|
-
var CLAUDE_OAUTH_CONFIG = {
|
|
281
|
-
clientId: "9d1c250a-e61b-44d9-88ed-5944d1962f5e",
|
|
282
|
-
authorizationEndpoint: "https://claude.ai/oauth/authorize",
|
|
283
|
-
// The token endpoint moved to platform.claude.com alongside the OAuth
|
|
284
|
-
// callback (the old console.anthropic.com/v1/oauth/token now returns
|
|
285
|
-
// Anthropic's standard 404 `{"error":{"type":"not_found_error","message":
|
|
286
|
-
// "Not found"}}` — observed 2026-06). The redirect_uri MUST match what the
|
|
287
|
-
// client is registered for AND match between authorize + token exchange.
|
|
288
|
-
// Scopes mirror the live Claude Code authorize URL.
|
|
289
|
-
tokenEndpoint: "https://platform.claude.com/v1/oauth/token",
|
|
290
|
-
redirectUri: "https://platform.claude.com/oauth/code/callback",
|
|
291
|
-
scopes: [
|
|
292
|
-
"org:create_api_key",
|
|
293
|
-
"user:profile",
|
|
294
|
-
"user:inference",
|
|
295
|
-
"user:sessions:claude_code",
|
|
296
|
-
"user:mcp_servers",
|
|
297
|
-
"user:file_upload"
|
|
298
|
-
]
|
|
299
|
-
};
|
|
300
|
-
var SETUP_TOKEN_CONFIG = {
|
|
301
|
-
scopes: ["user:inference"]
|
|
302
|
-
// Only inference permission, no API key creation
|
|
303
|
-
};
|
|
304
|
-
function generatePkce() {
|
|
305
|
-
const codeVerifier = _crypto2.default.randomBytes(32).toString("base64url");
|
|
306
|
-
const codeChallenge = _crypto2.default.createHash("sha256").update(codeVerifier).digest("base64url");
|
|
307
|
-
const state = _crypto2.default.randomBytes(16).toString("hex");
|
|
308
|
-
return { codeVerifier, codeChallenge, state };
|
|
309
|
-
}
|
|
310
|
-
function generateAuthParams() {
|
|
311
|
-
const { codeVerifier, codeChallenge, state } = generatePkce();
|
|
312
|
-
const params = new URLSearchParams({
|
|
313
|
-
code: "true",
|
|
314
|
-
client_id: CLAUDE_OAUTH_CONFIG.clientId,
|
|
315
|
-
response_type: "code",
|
|
316
|
-
redirect_uri: CLAUDE_OAUTH_CONFIG.redirectUri,
|
|
317
|
-
scope: CLAUDE_OAUTH_CONFIG.scopes.join(" "),
|
|
318
|
-
code_challenge: codeChallenge,
|
|
319
|
-
code_challenge_method: "S256",
|
|
320
|
-
state
|
|
321
|
-
});
|
|
322
|
-
const authUrl = `${CLAUDE_OAUTH_CONFIG.authorizationEndpoint}?${params.toString()}`;
|
|
323
|
-
return { authUrl, codeVerifier, state };
|
|
324
|
-
}
|
|
325
|
-
function generateSetupTokenParams() {
|
|
326
|
-
const { codeVerifier, codeChallenge, state } = generatePkce();
|
|
327
|
-
const params = new URLSearchParams({
|
|
328
|
-
code: "true",
|
|
329
|
-
client_id: CLAUDE_OAUTH_CONFIG.clientId,
|
|
330
|
-
response_type: "code",
|
|
331
|
-
redirect_uri: CLAUDE_OAUTH_CONFIG.redirectUri,
|
|
332
|
-
scope: SETUP_TOKEN_CONFIG.scopes.join(" "),
|
|
333
|
-
code_challenge: codeChallenge,
|
|
334
|
-
code_challenge_method: "S256",
|
|
335
|
-
state
|
|
336
|
-
});
|
|
337
|
-
const authUrl = `${CLAUDE_OAUTH_CONFIG.authorizationEndpoint}?${params.toString()}`;
|
|
338
|
-
return { authUrl, codeVerifier, state };
|
|
339
|
-
}
|
|
340
|
-
async function exchangeCodeForTokens(request, fetchImpl) {
|
|
341
|
-
const { authorizationCode, codeVerifier, state } = request;
|
|
342
|
-
const code = _nullishCoalesce(_optionalChain([authorizationCode, 'access', _3 => _3.split, 'call', _4 => _4("#"), 'access', _5 => _5[0], 'optionalAccess', _6 => _6.split, 'call', _7 => _7("&"), 'access', _8 => _8[0]]), () => ( authorizationCode));
|
|
343
|
-
const data = await postJson(
|
|
344
|
-
fetchImpl,
|
|
345
|
-
CLAUDE_OAUTH_CONFIG.tokenEndpoint,
|
|
346
|
-
{
|
|
347
|
-
grant_type: "authorization_code",
|
|
348
|
-
client_id: CLAUDE_OAUTH_CONFIG.clientId,
|
|
349
|
-
code,
|
|
350
|
-
code_verifier: codeVerifier,
|
|
351
|
-
redirect_uri: CLAUDE_OAUTH_CONFIG.redirectUri,
|
|
352
|
-
state
|
|
353
|
-
},
|
|
354
|
-
"Failed to parse token response",
|
|
355
|
-
CLAUDE_TOKEN_HEADERS
|
|
356
|
-
);
|
|
357
|
-
return {
|
|
358
|
-
accessToken: data.access_token,
|
|
359
|
-
// The authorization_code grant always returns a refresh_token; the original
|
|
360
|
-
// helper read it from an untyped `data` and declared the field `string`.
|
|
361
|
-
refreshToken: data.refresh_token,
|
|
362
|
-
expiresIn: data.expires_in,
|
|
363
|
-
scopes: _optionalChain([data, 'access', _9 => _9.scope, 'optionalAccess', _10 => _10.split, 'call', _11 => _11(" ")]) || CLAUDE_OAUTH_CONFIG.scopes
|
|
364
|
-
};
|
|
365
|
-
}
|
|
366
|
-
async function exchangeSetupTokenCode(request, fetchImpl) {
|
|
367
|
-
const { authorizationCode, codeVerifier, state } = request;
|
|
368
|
-
const code = _nullishCoalesce(_optionalChain([authorizationCode, 'access', _12 => _12.split, 'call', _13 => _13("#"), 'access', _14 => _14[0], 'optionalAccess', _15 => _15.split, 'call', _16 => _16("&"), 'access', _17 => _17[0]]), () => ( authorizationCode));
|
|
369
|
-
const data = await postJson(
|
|
370
|
-
fetchImpl,
|
|
371
|
-
CLAUDE_OAUTH_CONFIG.tokenEndpoint,
|
|
372
|
-
{
|
|
373
|
-
grant_type: "authorization_code",
|
|
374
|
-
client_id: CLAUDE_OAUTH_CONFIG.clientId,
|
|
375
|
-
code,
|
|
376
|
-
code_verifier: codeVerifier,
|
|
377
|
-
redirect_uri: CLAUDE_OAUTH_CONFIG.redirectUri,
|
|
378
|
-
state
|
|
379
|
-
},
|
|
380
|
-
"Failed to parse setup token response",
|
|
381
|
-
CLAUDE_TOKEN_HEADERS
|
|
382
|
-
);
|
|
383
|
-
return {
|
|
384
|
-
accessToken: data.access_token,
|
|
385
|
-
expiresIn: data.expires_in,
|
|
386
|
-
scopes: _optionalChain([data, 'access', _18 => _18.scope, 'optionalAccess', _19 => _19.split, 'call', _20 => _20(" ")]) || SETUP_TOKEN_CONFIG.scopes
|
|
387
|
-
};
|
|
388
|
-
}
|
|
389
|
-
async function refreshAccessToken2(refreshToken, fetchImpl) {
|
|
390
|
-
const data = await postJson(
|
|
391
|
-
fetchImpl,
|
|
392
|
-
CLAUDE_OAUTH_CONFIG.tokenEndpoint,
|
|
393
|
-
{
|
|
394
|
-
grant_type: "refresh_token",
|
|
395
|
-
client_id: CLAUDE_OAUTH_CONFIG.clientId,
|
|
396
|
-
refresh_token: refreshToken
|
|
397
|
-
},
|
|
398
|
-
"Failed to parse refresh response",
|
|
399
|
-
CLAUDE_TOKEN_HEADERS
|
|
400
|
-
);
|
|
401
|
-
return {
|
|
402
|
-
accessToken: data.access_token,
|
|
403
|
-
refreshToken: data.refresh_token || refreshToken,
|
|
404
|
-
expiresIn: data.expires_in
|
|
405
|
-
};
|
|
406
|
-
}
|
|
407
|
-
|
|
408
|
-
// src/oauth/flows/codex.ts
|
|
409
|
-
var codex_exports = {};
|
|
410
|
-
_chunk75ZPJI57cjs.__export.call(void 0, codex_exports, {
|
|
411
|
-
exchangeCodeForTokens: () => exchangeCodeForTokens2,
|
|
412
|
-
generateAuthParams: () => generateAuthParams2,
|
|
413
|
-
refreshAccessToken: () => refreshAccessToken3
|
|
414
|
-
});
|
|
415
|
-
|
|
416
|
-
var CODEX_OAUTH_CONFIG = {
|
|
417
|
-
clientId: "app_EMoamEEZ73f0CkXaXp7hrann",
|
|
418
|
-
authorizationEndpoint: "https://auth.openai.com/oauth/authorize",
|
|
419
|
-
tokenEndpoint: "https://auth.openai.com/oauth/token",
|
|
420
|
-
redirectUri: "http://localhost:1455/auth/callback",
|
|
421
|
-
scopes: ["openid", "profile", "email", "offline_access"]
|
|
422
|
-
};
|
|
423
|
-
function generateAuthParams2() {
|
|
424
|
-
const codeVerifier = _crypto2.default.randomBytes(64).toString("hex");
|
|
425
|
-
const codeChallenge = _crypto2.default.createHash("sha256").update(codeVerifier).digest("base64url");
|
|
426
|
-
const state = _crypto2.default.randomBytes(16).toString("hex");
|
|
427
|
-
const params = new URLSearchParams({
|
|
428
|
-
response_type: "code",
|
|
429
|
-
client_id: CODEX_OAUTH_CONFIG.clientId,
|
|
430
|
-
redirect_uri: CODEX_OAUTH_CONFIG.redirectUri,
|
|
431
|
-
scope: CODEX_OAUTH_CONFIG.scopes.join(" "),
|
|
432
|
-
code_challenge: codeChallenge,
|
|
433
|
-
code_challenge_method: "S256",
|
|
434
|
-
state
|
|
435
|
-
});
|
|
436
|
-
const authUrl = `${CODEX_OAUTH_CONFIG.authorizationEndpoint}?${params.toString()}`;
|
|
437
|
-
return { authUrl, codeVerifier, state };
|
|
438
|
-
}
|
|
439
|
-
async function exchangeCodeForTokens2(request, fetchImpl) {
|
|
440
|
-
const { authorizationCode, codeVerifier } = request;
|
|
441
|
-
const params = new URLSearchParams({
|
|
442
|
-
grant_type: "authorization_code",
|
|
443
|
-
client_id: CODEX_OAUTH_CONFIG.clientId,
|
|
444
|
-
code: authorizationCode,
|
|
445
|
-
code_verifier: codeVerifier,
|
|
446
|
-
redirect_uri: CODEX_OAUTH_CONFIG.redirectUri
|
|
447
|
-
});
|
|
448
|
-
const data = await postForm(
|
|
449
|
-
fetchImpl,
|
|
450
|
-
CODEX_OAUTH_CONFIG.tokenEndpoint,
|
|
451
|
-
params,
|
|
452
|
-
"Failed to parse token response"
|
|
453
|
-
);
|
|
454
|
-
return {
|
|
455
|
-
accessToken: data.access_token,
|
|
456
|
-
// authorization_code grant returns both; the original helper read them from
|
|
457
|
-
// an untyped `data` and declared the fields `string`.
|
|
458
|
-
refreshToken: data.refresh_token,
|
|
459
|
-
idToken: data.id_token,
|
|
460
|
-
expiresIn: data.expires_in
|
|
461
|
-
};
|
|
462
|
-
}
|
|
463
|
-
async function refreshAccessToken3(refreshToken, fetchImpl) {
|
|
464
|
-
const params = new URLSearchParams({
|
|
465
|
-
grant_type: "refresh_token",
|
|
466
|
-
client_id: CODEX_OAUTH_CONFIG.clientId,
|
|
467
|
-
refresh_token: refreshToken,
|
|
468
|
-
scope: "openid profile email"
|
|
469
|
-
});
|
|
470
|
-
const data = await postForm(
|
|
471
|
-
fetchImpl,
|
|
472
|
-
CODEX_OAUTH_CONFIG.tokenEndpoint,
|
|
473
|
-
params,
|
|
474
|
-
"Failed to parse refresh response"
|
|
475
|
-
);
|
|
476
|
-
return {
|
|
477
|
-
accessToken: data.access_token,
|
|
478
|
-
idToken: data.id_token,
|
|
479
|
-
refreshToken: data.refresh_token || refreshToken,
|
|
480
|
-
expiresIn: data.expires_in || 3600
|
|
481
|
-
};
|
|
482
|
-
}
|
|
483
|
-
|
|
484
|
-
// src/oauth/flows/gemini.ts
|
|
485
|
-
var gemini_exports = {};
|
|
486
|
-
_chunk75ZPJI57cjs.__export.call(void 0, gemini_exports, {
|
|
487
|
-
exchangeCodeForTokens: () => exchangeCodeForTokens3,
|
|
488
|
-
generateAuthParams: () => generateAuthParams3,
|
|
489
|
-
refreshAccessToken: () => refreshAccessToken4
|
|
490
|
-
});
|
|
491
|
-
|
|
492
|
-
var GEMINI_OAUTH_CONFIG = {
|
|
493
|
-
clientId: "681255809395-oo8ft2oprdrnp9e3aqf6av3hmdib135j.apps.googleusercontent.com",
|
|
494
|
-
// The Gemini CLI's *public* installed-app OAuth client secret (mirrors the
|
|
495
|
-
// upstream CLI). Per Google's OAuth docs, native-app client secrets are not
|
|
496
|
-
// treated as confidential — not a leaked key.
|
|
497
|
-
clientSecret: "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",
|
|
498
|
-
// allowlist-secret
|
|
499
|
-
authorizationEndpoint: "https://accounts.google.com/o/oauth2/v2/auth",
|
|
500
|
-
tokenEndpoint: "https://oauth2.googleapis.com/token",
|
|
501
|
-
redirectUri: "urn:ietf:wg:oauth:2.0:oob",
|
|
502
|
-
scopes: ["https://www.googleapis.com/auth/cloud-platform"]
|
|
503
|
-
};
|
|
504
|
-
function generateAuthParams3() {
|
|
505
|
-
const codeVerifier = _crypto2.default.randomBytes(32).toString("base64url");
|
|
506
|
-
const codeChallenge = _crypto2.default.createHash("sha256").update(codeVerifier).digest("base64url");
|
|
507
|
-
const state = _crypto2.default.randomBytes(16).toString("hex");
|
|
508
|
-
const params = new URLSearchParams({
|
|
509
|
-
client_id: GEMINI_OAUTH_CONFIG.clientId,
|
|
510
|
-
redirect_uri: GEMINI_OAUTH_CONFIG.redirectUri,
|
|
511
|
-
scope: GEMINI_OAUTH_CONFIG.scopes.join(" "),
|
|
512
|
-
response_type: "code",
|
|
513
|
-
code_challenge: codeChallenge,
|
|
514
|
-
code_challenge_method: "S256",
|
|
515
|
-
state,
|
|
516
|
-
access_type: "offline",
|
|
517
|
-
prompt: "consent"
|
|
518
|
-
});
|
|
519
|
-
const authUrl = `${GEMINI_OAUTH_CONFIG.authorizationEndpoint}?${params.toString()}`;
|
|
520
|
-
return { authUrl, codeVerifier, state };
|
|
521
|
-
}
|
|
522
|
-
async function exchangeCodeForTokens3(authorizationCode, codeVerifier, fetchImpl) {
|
|
523
|
-
const params = new URLSearchParams({
|
|
524
|
-
grant_type: "authorization_code",
|
|
525
|
-
client_id: GEMINI_OAUTH_CONFIG.clientId,
|
|
526
|
-
client_secret: GEMINI_OAUTH_CONFIG.clientSecret,
|
|
527
|
-
code: authorizationCode,
|
|
528
|
-
code_verifier: codeVerifier,
|
|
529
|
-
redirect_uri: GEMINI_OAUTH_CONFIG.redirectUri
|
|
530
|
-
});
|
|
531
|
-
const data = await postForm(
|
|
532
|
-
fetchImpl,
|
|
533
|
-
GEMINI_OAUTH_CONFIG.tokenEndpoint,
|
|
534
|
-
params,
|
|
535
|
-
"Failed to parse token response"
|
|
536
|
-
);
|
|
537
|
-
return {
|
|
538
|
-
accessToken: data.access_token,
|
|
539
|
-
// authorization_code grant returns a refresh_token; the original helper read
|
|
540
|
-
// it from an untyped `data` and declared the field `string`.
|
|
541
|
-
refreshToken: data.refresh_token,
|
|
542
|
-
expiresIn: data.expires_in
|
|
543
|
-
};
|
|
544
|
-
}
|
|
545
|
-
async function refreshAccessToken4(refreshToken, fetchImpl) {
|
|
546
|
-
const params = new URLSearchParams({
|
|
547
|
-
grant_type: "refresh_token",
|
|
548
|
-
client_id: GEMINI_OAUTH_CONFIG.clientId,
|
|
549
|
-
client_secret: GEMINI_OAUTH_CONFIG.clientSecret,
|
|
550
|
-
refresh_token: refreshToken
|
|
551
|
-
});
|
|
552
|
-
const data = await postForm(
|
|
553
|
-
fetchImpl,
|
|
554
|
-
GEMINI_OAUTH_CONFIG.tokenEndpoint,
|
|
555
|
-
params,
|
|
556
|
-
"Failed to parse refresh response"
|
|
557
|
-
);
|
|
558
|
-
return {
|
|
559
|
-
accessToken: data.access_token,
|
|
560
|
-
expiresIn: data.expires_in
|
|
561
|
-
};
|
|
562
|
-
}
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
exports.kimiFingerprintHeaders = kimiFingerprintHeaders; exports.kimi_exports = kimi_exports; exports.claude_exports = claude_exports; exports.codex_exports = codex_exports; exports.gemini_exports = gemini_exports;
|