forked from decolua/9router
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoauth.js
More file actions
231 lines (202 loc) · 9.37 KB
/
Copy pathoauth.js
File metadata and controls
231 lines (202 loc) · 9.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
/**
* OAuth Configuration Constants — static data lives in registry, re-exported here for consumers.
*/
import { platform, arch } from "os";
import { ANTIGRAVITY_OAUTH_CLIENT, GOOGLE_OAUTH_CLIENT } from "open-sse/providers/shared.js";
import { PROVIDER_OAUTH, PROVIDERS as REGISTRY_PROVIDERS } from "open-sse/providers/index.js";
/**
* Get the platform enum value based on the current OS.
* Matches Antigravity binary's ClientMetadata.Platform enum.
*/
function getOAuthPlatformEnum() {
const os = platform();
const architecture = arch();
if (os === "darwin") return architecture === "arm64" ? 2 : 1;
if (os === "linux") return architecture === "arm64" ? 4 : 3;
if (os === "win32") return 5;
return 0;
}
// Claude OAuth Configuration (Authorization Code Flow with PKCE)
export const CLAUDE_CONFIG = { ...PROVIDER_OAUTH["claude"] };
// Codex (OpenAI) OAuth Configuration (Authorization Code Flow with PKCE)
export const CODEX_CONFIG = { ...PROVIDER_OAUTH["codex"] };
// Gemini (Google) OAuth Configuration (Standard OAuth2)
// clientId/clientSecret from GOOGLE_OAUTH_CLIENT (shared.js) — not stored in registry
export const GEMINI_CONFIG = { ...GOOGLE_OAUTH_CLIENT, ...PROVIDER_OAUTH["gemini-cli"] };
// Qoder OAuth Configuration (Device Token Flow with PKCE).
// Device tokens are long-lived (~30 days for access, ~360 for refresh).
// The upstream refresh endpoint at center.qoder.sh returns 403 for our
// flow — we accept that and surface it to the user as "re-login" instead
// of attempting to silently rotate.
export const QODER_CONFIG = { ...PROVIDER_OAUTH["qoder"] };
// iFlow OAuth Configuration (Authorization Code)
export const IFLOW_CONFIG = { ...PROVIDER_OAUTH["iflow"] };
// Antigravity OAuth Configuration (Standard OAuth2 with Google)
// clientId/clientSecret from ANTIGRAVITY_OAUTH_CLIENT (shared.js) — not stored in registry
// loadCodeAssistClientMetadata is dynamic (runtime platform detection)
export const ANTIGRAVITY_CONFIG = {
...ANTIGRAVITY_OAUTH_CLIENT,
...PROVIDER_OAUTH["antigravity"],
loadCodeAssistClientMetadata: JSON.stringify({ ideType: 9, platform: getOAuthPlatformEnum(), pluginType: 2 }),
};
/**
* Get client metadata using numeric enum values for API calls.
* @returns {{ ideType: number, platform: number, pluginType: number }}
*/
export function getOAuthClientMetadata() {
return { ideType: 9, platform: getOAuthPlatformEnum(), pluginType: 2 };
}
// OpenAI OAuth Configuration (Authorization Code Flow with PKCE)
export const OPENAI_CONFIG = { ...PROVIDER_OAUTH["openai"] };
// GitHub Copilot OAuth Configuration (Device Code Flow)
export const GITHUB_CONFIG = { ...PROVIDER_OAUTH["github"] };
// Kiro OAuth Configuration (multi-method: AWS Builder ID / IDC / Social / Import Token)
export const KIRO_CONFIG = { ...PROVIDER_OAUTH["kiro"] };
// AWS region allowlist pattern — prevents SSRF via region injection into upstream URLs (GHSA-6mwv-4mrm-5p3m)
export const AWS_REGION_PATTERN = /^[a-z]{2}-[a-z]+-\d{1,2}$/;
// Reject any region that is not a valid AWS region before interpolating it into a URL
export function assertValidAwsRegion(region) {
if (typeof region !== "string" || !AWS_REGION_PATTERN.test(region)) {
throw new Error("Invalid region");
}
return region;
}
// Cursor OAuth Configuration (Import Token from Cursor IDE)
// tokenStoragePaths: user-reference only, not stored in registry
export const CURSOR_CONFIG = {
...PROVIDER_OAUTH["cursor"],
tokenStoragePaths: {
linux: "~/.config/Cursor/User/globalStorage/state.vscdb",
macos: "/Users/<user>/Library/Application Support/Cursor/User/globalStorage/state.vscdb",
windows: "%APPDATA%\\Cursor\\User\\globalStorage\\state.vscdb",
},
};
// Raycast Pro AI OAuth Configuration (token import — reverse-engineered, unofficial API).
// Captured Bearer + X-Raycast-DeviceId (+ optional X-Raycast-Signature JWT) required.
export const RAYCAST_CONFIG = { ...PROVIDER_OAUTH["raycast"] };
// Kimi Code OAuth (Device Code Flow) — merged into provider id `kimi` (dual auth)
// clientId: registry first, env override for forks
export const KIMI_CONFIG = {
...PROVIDER_OAUTH["kimi"],
clientId:
process.env.KIMI_CODING_OAUTH_CLIENT_ID ||
process.env.KIMI_OAUTH_CLIENT_ID ||
REGISTRY_PROVIDERS["kimi"]?.clientId ||
PROVIDER_OAUTH["kimi"]?.clientId,
};
// Back-compat alias for any remaining KIMI_CODING_CONFIG imports
export const KIMI_CODING_CONFIG = KIMI_CONFIG;
// KiloCode OAuth Configuration (Custom Device Auth Flow)
export const KILOCODE_CONFIG = { ...PROVIDER_OAUTH["kilocode"] };
// Cline OAuth Configuration (Local Callback Flow via app.cline.bot)
export const CLINE_CONFIG = { ...PROVIDER_OAUTH["cline"] };
// ClinePass OAuth Configuration (shares Cline's OAuth endpoints)
export const CLINEPASS_CONFIG = { ...PROVIDER_OAUTH["clinepass"] };
// GitLab Duo OAuth Configuration (Authorization Code Flow with PKCE)
export const GITLAB_CONFIG = { ...PROVIDER_OAUTH["gitlab"] };
// CodeBuddy (Tencent) OAuth Configuration (Browser OAuth Polling Flow)
export const CODEBUDDY_CONFIG = { ...PROVIDER_OAUTH["codebuddy-cn"] };
// CodeBuddy International — same shape as CN, .ai domain (mirror of codebuddy-cn).
export const CODEBUDDY_INTL_CONFIG = { ...PROVIDER_OAUTH["codebuddy-intl"] };
// Kimchi OAuth Configuration (Browser token callback flow)
export const KIMCHI_CONFIG = { ...PROVIDER_OAUTH["kimchi"] };
// Grok CLI / Grok Build OAuth Configuration (Device Code Flow)
// Endpoint: cli-chat-proxy.grok.com — same client_id as xai, different flow + scopes
export const GROK_CLI_CONFIG = { ...PROVIDER_OAUTH["grok-cli"] };
// Trae (ByteDance marscode) OAuth — authorization_code flow with local callback.
// 1) POST GetLoginGuidance {loginTraceID} → {Result.LoginHost}
// 2) Browser opens ${loginHost}/authorization?client_id=...&login_trace_id=...&auth_callback_url=${cb}
// 3) Redirect → ${cb}?refreshToken=...&loginHost=...&isRedirect=true
// 4) POST ExchangeToken {ClientID, RefreshToken, ClientSecret:"-"} → {Result.AccessToken, ExpiresAt}
// 5) POST GetUserInfo (x-cloudide-token) → email/name
export const TRAE_CONFIG = {
clientId: "ono9krqynydwx5",
clientSecret: "-",
loginGuidanceUrls: [
"https://api.marscode.com/cloudide/api/v3/trae/GetLoginGuidance",
"https://api.trae.ai/cloudide/api/v3/trae/GetLoginGuidance",
"https://www.trae.ai/cloudide/api/v3/trae/GetLoginGuidance",
],
apiOrigins: [
"https://api.marscode.com",
"https://api.trae.ai",
"https://www.trae.ai",
"https://www.marscode.com",
],
exchangeTokenPath: "/cloudide/api/v3/trae/oauth/ExchangeToken",
getUserInfoPath: "/cloudide/api/v3/trae/GetUserInfo",
authorizationPath: "/authorization",
callbackPath: "/callback",
minAppVersion: "3.5.54",
defaultAppVersion: "3.5.54",
defaultAppType: "stable",
defaultPluginVersion: "local",
// service machine id is derived at runtime; device_id "0" is the stable default
defaultDeviceId: "0",
userAgent: "Trae/1.0.0 antigravity-cockpit-tools",
webUrl: "https://www.trae.ai",
authScheme: "Cloud-IDE-JWT",
tokenLifetimeDays: 14,
oauthTimeoutMs: 600_000,
};
// Windsurf / Devin CLI OAuth — authorization_code (implicit) flow with local callback.
// 1) Browser opens windsurf.com/windsurf/signin?response_type=token&client_id=...&redirect_uri=${cb}
// 2) Redirect → ${cb}?access_token=${firebaseJWT}&state=...
// 3) POST RegisterUser {firebase_id_token} → {apiKey, apiServerUrl, name}
// 4) POST GetOneTimeAuthToken → GetCurrentUser (best-effort email/plan)
export const WINDSURF_CONFIG = {
clientId: "3GUryQ7ldAeKEuD2obYnppsnmj58eP5u",
authBaseUrl: "https://www.windsurf.com",
signInPath: "/windsurf/signin",
registerApiBaseUrl: "https://register.windsurf.com",
registerPath: "/exa.seat_management_pb.SeatManagementService/RegisterUser",
oneTimeAuthPath: "/exa.seat_management_pb.SeatManagementService/GetOneTimeAuthToken",
currentUserPath: "/exa.seat_management_pb.SeatManagementService/GetCurrentUser",
planStatusPath: "/exa.seat_management_pb.SeatManagementService/GetPlanStatus",
userStatusPath: "/exa.seat_management_pb.SeatManagementService/GetUserStatus",
defaultApiServerUrl: "https://server.codeium.com",
firebaseApiKey: "AIzaSyDsOl-1XpT5err0Tcn0TFFod1H8gVGIycY",
callbackPath: "/windsurf-auth-callback",
userAgent: "antigravity-cockpit-tools",
oauthTimeoutMs: 600_000,
};
// Zed hosted LLM aggregator — RSA keypair native-app auth (NOT OAuth).
// Client generates ephemeral RSA-2048 keypair; user signs in at zed.dev/native_app_signin;
// Zed redirects to local callback with access_token RSA-encrypted against our public key.
// See open-sse/shared/zedAuth.js for the keypair/decrypt helpers.
export const ZED_HOSTED_CONFIG = {
webBaseUrl: "https://zed.dev",
cloudBaseUrl: "https://cloud.zed.dev",
llmBaseUrl: "https://cloud.zed.dev",
defaultNativeAppPort: 58443,
oauthTimeoutMs: 600_000,
};
// OAuth timeout (5 minutes)
export const OAUTH_TIMEOUT = 300000;
// Provider list
export const PROVIDERS = {
CLAUDE: "claude",
CODEX: "codex",
GEMINI: "gemini-cli",
QODER: "qoder",
IFLOW: "iflow",
ANTIGRAVITY: "antigravity",
OPENAI: "openai",
GITHUB: "github",
KIRO: "kiro",
CURSOR: "cursor",
KIMI: "kimi",
KIMI_CODING: "kimi",
KILOCODE: "kilocode",
CLINE: "cline",
CLINEPASS: "clinepass",
GITLAB: "gitlab",
CODEBUDDY: "codebuddy-cn",
CODEBUDDY_INTL: "codebuddy-intl",
KIMCHI: "kimchi",
GROK_CLI: "grok-cli",
TRAE: "trae",
WINDSURF: "windsurf",
ZED: "zed",
RAYCAST: "raycast",
};