mirror of
https://github.com/Nezumi-2711/9router.git
synced 2026-09-22 20:00:47 +00:00
- Add CursorExecutor for handling requests to the Cursor API using protobuf over HTTP/2. - Implement CursorAuthModal for user token import from local SQLite database. - Update provider models and constants to include Cursor as a supported provider. - Enhance API service with token validation and user info extraction from Cursor tokens. - Introduce utility functions for checksum generation and protobuf encoding/decoding for Cursor API interactions.
189 lines
7.3 KiB
JavaScript
189 lines
7.3 KiB
JavaScript
/**
|
|
* OAuth Configuration Constants
|
|
*/
|
|
|
|
// Claude OAuth Configuration (Authorization Code Flow with PKCE)
|
|
export const CLAUDE_CONFIG = {
|
|
clientId: "9d1c250a-e61b-44d9-88ed-5944d1962f5e",
|
|
authorizeUrl: "https://claude.ai/oauth/authorize",
|
|
tokenUrl: "https://console.anthropic.com/v1/oauth/token",
|
|
scopes: ["org:create_api_key", "user:profile", "user:inference"],
|
|
codeChallengeMethod: "S256",
|
|
};
|
|
|
|
// Codex (OpenAI) OAuth Configuration (Authorization Code Flow with PKCE)
|
|
export const CODEX_CONFIG = {
|
|
clientId: "app_EMoamEEZ73f0CkXaXp7hrann",
|
|
authorizeUrl: "https://auth.openai.com/oauth/authorize",
|
|
tokenUrl: "https://auth.openai.com/oauth/token",
|
|
scope: "openid profile email offline_access",
|
|
codeChallengeMethod: "S256",
|
|
// Additional OpenAI-specific params
|
|
extraParams: {
|
|
id_token_add_organizations: "true",
|
|
codex_cli_simplified_flow: "true",
|
|
originator: "codex_cli_rs",
|
|
},
|
|
};
|
|
|
|
// Gemini (Google) OAuth Configuration (Standard OAuth2)
|
|
export const GEMINI_CONFIG = {
|
|
clientId: "681255809395-oo8ft2oprdrnp9e3aqf6av3hmdib135j.apps.googleusercontent.com",
|
|
clientSecret: "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",
|
|
authorizeUrl: "https://accounts.google.com/o/oauth2/v2/auth",
|
|
tokenUrl: "https://oauth2.googleapis.com/token",
|
|
userInfoUrl: "https://www.googleapis.com/oauth2/v1/userinfo",
|
|
scopes: [
|
|
"https://www.googleapis.com/auth/cloud-platform",
|
|
"https://www.googleapis.com/auth/userinfo.email",
|
|
"https://www.googleapis.com/auth/userinfo.profile",
|
|
],
|
|
};
|
|
|
|
// Qwen OAuth Configuration (Device Code Flow with PKCE)
|
|
export const QWEN_CONFIG = {
|
|
clientId: "f0304373b74a44d2b584a3fb70ca9e56",
|
|
deviceCodeUrl: "https://chat.qwen.ai/api/v1/oauth2/device/code",
|
|
tokenUrl: "https://chat.qwen.ai/api/v1/oauth2/token",
|
|
scope: "openid profile email model.completion",
|
|
codeChallengeMethod: "S256",
|
|
};
|
|
|
|
// iFlow OAuth Configuration (Authorization Code)
|
|
export const IFLOW_CONFIG = {
|
|
clientId: "10009311001",
|
|
clientSecret: "4Z3YjXycVsQvyGF1etiNlIBB4RsqSDtW",
|
|
authorizeUrl: "https://iflow.cn/oauth",
|
|
tokenUrl: "https://iflow.cn/oauth/token",
|
|
userInfoUrl: "https://iflow.cn/api/oauth/getUserInfo",
|
|
extraParams: {
|
|
loginMethod: "phone",
|
|
type: "phone",
|
|
},
|
|
};
|
|
|
|
// Antigravity OAuth Configuration (Standard OAuth2 with Google)
|
|
export const ANTIGRAVITY_CONFIG = {
|
|
clientId: "1071006060591-tmhssin2h21lcre235vtolojh4g403ep.apps.googleusercontent.com",
|
|
clientSecret: "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",
|
|
authorizeUrl: "https://accounts.google.com/o/oauth2/v2/auth",
|
|
tokenUrl: "https://oauth2.googleapis.com/token",
|
|
userInfoUrl: "https://www.googleapis.com/oauth2/v1/userinfo",
|
|
scopes: [
|
|
"https://www.googleapis.com/auth/cloud-platform",
|
|
"https://www.googleapis.com/auth/userinfo.email",
|
|
"https://www.googleapis.com/auth/userinfo.profile",
|
|
"https://www.googleapis.com/auth/cclog",
|
|
"https://www.googleapis.com/auth/experimentsandconfigs",
|
|
],
|
|
// Antigravity specific
|
|
apiEndpoint: "https://cloudcode-pa.googleapis.com",
|
|
apiVersion: "v1internal",
|
|
loadCodeAssistEndpoint: "https://cloudcode-pa.googleapis.com/v1internal:loadCodeAssist",
|
|
onboardUserEndpoint: "https://cloudcode-pa.googleapis.com/v1internal:onboardUser",
|
|
loadCodeAssistUserAgent: "google-api-nodejs-client/9.15.1",
|
|
loadCodeAssistApiClient: "google-cloud-sdk vscode_cloudshelleditor/0.1",
|
|
loadCodeAssistClientMetadata: `{"ideType":"IDE_UNSPECIFIED","platform":"PLATFORM_UNSPECIFIED","pluginType":"GEMINI"}`,
|
|
};
|
|
|
|
// OpenAI OAuth Configuration (Authorization Code Flow with PKCE)
|
|
export const OPENAI_CONFIG = {
|
|
clientId: "app_EMoamEEZ73f0CkXaXp7hrann",
|
|
authorizeUrl: "https://auth.openai.com/oauth/authorize",
|
|
tokenUrl: "https://auth.openai.com/oauth/token",
|
|
scope: "openid profile email offline_access",
|
|
codeChallengeMethod: "S256",
|
|
extraParams: {
|
|
id_token_add_organizations: "true",
|
|
originator: "openai_native",
|
|
},
|
|
};
|
|
|
|
// GitHub Copilot OAuth Configuration (Device Code Flow)
|
|
export const GITHUB_CONFIG = {
|
|
clientId: "Iv1.b507a08c87ecfe98",
|
|
deviceCodeUrl: "https://github.com/login/device/code",
|
|
tokenUrl: "https://github.com/login/oauth/access_token",
|
|
userInfoUrl: "https://api.github.com/user",
|
|
scopes: "read:user",
|
|
apiVersion: "2022-11-28", // Updated to supported version
|
|
copilotTokenUrl: "https://api.github.com/copilot_internal/v2/token",
|
|
userAgent: "GitHubCopilotChat/0.26.7",
|
|
editorVersion: "vscode/1.85.0",
|
|
editorPluginVersion: "copilot-chat/0.26.7",
|
|
};
|
|
|
|
// Kiro OAuth Configuration
|
|
// Supports multiple auth methods:
|
|
// 1. AWS Builder ID (Device Code Flow)
|
|
// 2. AWS IAM Identity Center/IDC (Device Code Flow with custom startUrl/region)
|
|
// 3. Google/GitHub Social Login (Authorization Code Flow - manual callback)
|
|
// 4. Import Token (paste refresh token from Kiro IDE)
|
|
export const KIRO_CONFIG = {
|
|
// AWS SSO OIDC endpoints for Builder ID/IDC (Device Code Flow)
|
|
ssoOidcEndpoint: "https://oidc.us-east-1.amazonaws.com",
|
|
registerClientUrl: "https://oidc.us-east-1.amazonaws.com/client/register",
|
|
deviceAuthUrl: "https://oidc.us-east-1.amazonaws.com/device_authorization",
|
|
tokenUrl: "https://oidc.us-east-1.amazonaws.com/token",
|
|
// AWS Builder ID default start URL
|
|
startUrl: "https://view.awsapps.com/start",
|
|
// Client registration params
|
|
clientName: "kiro-oauth-client",
|
|
clientType: "public",
|
|
scopes: ["codewhisperer:completions", "codewhisperer:analysis", "codewhisperer:conversations"],
|
|
grantTypes: ["urn:ietf:params:oauth:grant-type:device_code", "refresh_token"],
|
|
issuerUrl: "https://identitycenter.amazonaws.com/ssoins-722374e8c3c8e6c6",
|
|
// Social auth endpoints (Google/GitHub via AWS Cognito)
|
|
socialAuthEndpoint: "https://prod.us-east-1.auth.desktop.kiro.dev",
|
|
socialLoginUrl: "https://prod.us-east-1.auth.desktop.kiro.dev/login",
|
|
socialTokenUrl: "https://prod.us-east-1.auth.desktop.kiro.dev/oauth/token",
|
|
socialRefreshUrl: "https://prod.us-east-1.auth.desktop.kiro.dev/refreshToken",
|
|
// Auth methods
|
|
authMethods: ["builder-id", "idc", "google", "github", "import"],
|
|
};
|
|
|
|
// Cursor OAuth Configuration (Import Token from Cursor IDE)
|
|
// Cursor stores credentials in SQLite database: state.vscdb
|
|
// Keys: cursorAuth/accessToken, storage.serviceMachineId
|
|
export const CURSOR_CONFIG = {
|
|
// API endpoints
|
|
apiEndpoint: "https://api2.cursor.sh",
|
|
chatEndpoint: "/aiserver.v1.ChatService/StreamUnifiedChatWithTools",
|
|
modelsEndpoint: "/aiserver.v1.AiService/GetDefaultModelNudgeData",
|
|
// Additional endpoints
|
|
api3Endpoint: "https://api3.cursor.sh", // Telemetry
|
|
agentEndpoint: "https://agent.api5.cursor.sh", // Privacy mode
|
|
agentNonPrivacyEndpoint: "https://agentn.api5.cursor.sh", // Non-privacy mode
|
|
// Client metadata
|
|
clientVersion: "0.48.6",
|
|
clientType: "ide",
|
|
// Token storage locations (for user reference)
|
|
tokenStoragePaths: {
|
|
linux: "~/.config/Cursor/User/globalStorage/state.vscdb",
|
|
macos: "~/Library/Application Support/Cursor/User/globalStorage/state.vscdb",
|
|
windows: "%APPDATA%\\Cursor\\User\\globalStorage\\state.vscdb",
|
|
},
|
|
// Database keys
|
|
dbKeys: {
|
|
accessToken: "cursorAuth/accessToken",
|
|
machineId: "storage.serviceMachineId",
|
|
},
|
|
};
|
|
|
|
// OAuth timeout (5 minutes)
|
|
export const OAUTH_TIMEOUT = 300000;
|
|
|
|
// Provider list
|
|
export const PROVIDERS = {
|
|
CLAUDE: "claude",
|
|
CODEX: "codex",
|
|
GEMINI: "gemini-cli",
|
|
QWEN: "qwen",
|
|
IFLOW: "iflow",
|
|
ANTIGRAVITY: "antigravity",
|
|
OPENAI: "openai",
|
|
GITHUB: "github",
|
|
KIRO: "kiro",
|
|
CURSOR: "cursor",
|
|
};
|