omp-multi-auth 1.1.1 → 1.2.0
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/README.md +3 -1
- package/extensions/lib/providers.ts +57 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -99,7 +99,9 @@ Create `.omp/multi-auth.json` in a project to restrict which subscription provid
|
|
|
99
99
|
|
|
100
100
|
API-key providers support full multi-account operation. Add an account with `/multi-auth add`, select the provider, then authenticate via `/multi-auth login` (or `/login <name>`) and paste your API key when prompted. Each account stores its own key independently in OMP auth storage.
|
|
101
101
|
|
|
102
|
-
Cursor
|
|
102
|
+
- `cursor`: Cursor dashboard API keys (`crsr_...`/`cursor_...`) exchanged for short-lived session JWTs and automatically refreshed.
|
|
103
|
+
|
|
104
|
+
GitLab Duo requires custom handlers and is not exposed.
|
|
103
105
|
|
|
104
106
|
## Built-in limits
|
|
105
107
|
|
|
@@ -88,6 +88,56 @@ export function buildApiKeyOAuth(displayName: string, index: number, placeholder
|
|
|
88
88
|
};
|
|
89
89
|
}
|
|
90
90
|
|
|
91
|
+
const CURSOR_EXCHANGE_URL = "https://api2.cursor.sh/auth/exchange_user_api_key";
|
|
92
|
+
|
|
93
|
+
function cursorJwtExpiryMs(jwt: string): number {
|
|
94
|
+
const fallback = Date.now() + 55 * 60 * 1000;
|
|
95
|
+
const parts = jwt.split(".");
|
|
96
|
+
if (parts.length !== 3) return fallback;
|
|
97
|
+
try {
|
|
98
|
+
const payload = JSON.parse(atob(parts[1].replace(/-/g, "+").replace(/_/g, "/"))) as { exp?: number };
|
|
99
|
+
return typeof payload.exp === "number" ? payload.exp * 1000 : fallback;
|
|
100
|
+
} catch {
|
|
101
|
+
return fallback;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
async function exchangeCursorApiKey(apiKey: string, signal?: AbortSignal): Promise<OAuthCredentials> {
|
|
106
|
+
const resp = await fetch(CURSOR_EXCHANGE_URL, {
|
|
107
|
+
method: "POST",
|
|
108
|
+
headers: { Authorization: `Bearer ${apiKey}`, "Content-Type": "application/json" },
|
|
109
|
+
body: "{}",
|
|
110
|
+
signal,
|
|
111
|
+
});
|
|
112
|
+
if (!resp.ok) {
|
|
113
|
+
const text = await resp.text().catch(() => "");
|
|
114
|
+
throw new Error(`Cursor API key exchange failed (${resp.status}): ${text || resp.statusText}`);
|
|
115
|
+
}
|
|
116
|
+
const data = (await resp.json()) as { accessToken?: string };
|
|
117
|
+
if (!data.accessToken) throw new Error("Cursor API key exchange returned no accessToken");
|
|
118
|
+
return { access: data.accessToken, refresh: apiKey, expires: cursorJwtExpiryMs(data.accessToken) };
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
export function buildCursorApiKeyOAuth(index: number): ProviderOAuth {
|
|
122
|
+
return {
|
|
123
|
+
name: `Cursor #${index}`,
|
|
124
|
+
async login(callbacks: OAuthLoginCallbacks): Promise<OAuthCredentials> {
|
|
125
|
+
const apiKey = (await callbacks.onPrompt({
|
|
126
|
+
message: "Paste your Cursor API key (crsr_...):",
|
|
127
|
+
placeholder: "crsr_...",
|
|
128
|
+
})).trim();
|
|
129
|
+
if (!apiKey) throw new Error(`No API key entered for Cursor #${index}`);
|
|
130
|
+
return exchangeCursorApiKey(apiKey);
|
|
131
|
+
},
|
|
132
|
+
async refreshToken(credentials: OAuthCredentials): Promise<OAuthCredentials> {
|
|
133
|
+
return exchangeCursorApiKey(credentials.refresh || credentials.access);
|
|
134
|
+
},
|
|
135
|
+
getApiKey(credentials: OAuthCredentials): string {
|
|
136
|
+
return credentials.access;
|
|
137
|
+
},
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
|
|
91
141
|
|
|
92
142
|
|
|
93
143
|
// GitHub Copilot base URL derivation, ported from the pi-ai OAuth flow
|
|
@@ -319,6 +369,13 @@ export const PROVIDER_TEMPLATES: Record<string, ProviderTemplate> = {
|
|
|
319
369
|
},
|
|
320
370
|
},
|
|
321
371
|
|
|
372
|
+
cursor: {
|
|
373
|
+
displayName: "Cursor (API key)",
|
|
374
|
+
buildOAuth(index: number) {
|
|
375
|
+
return buildCursorApiKeyOAuth(index);
|
|
376
|
+
},
|
|
377
|
+
},
|
|
378
|
+
|
|
322
379
|
};
|
|
323
380
|
|
|
324
381
|
for (const spec of API_KEY_PROVIDERS) {
|
package/package.json
CHANGED