mirror of
https://github.com/router-for-me/Cli-Proxy-API-Management-Center.git
synced 2026-02-03 19:30:51 +08:00
feat(oauth): add callback URL submission and require Gemini CLI project ID
This commit is contained in:
@@ -17,6 +17,10 @@ export interface OAuthStartResponse {
|
||||
state?: string;
|
||||
}
|
||||
|
||||
export interface OAuthCallbackResponse {
|
||||
status: 'ok';
|
||||
}
|
||||
|
||||
export interface IFlowCookieAuthResponse {
|
||||
status: 'ok' | 'error';
|
||||
error?: string;
|
||||
@@ -27,18 +31,37 @@ export interface IFlowCookieAuthResponse {
|
||||
}
|
||||
|
||||
const WEBUI_SUPPORTED: OAuthProvider[] = ['codex', 'anthropic', 'antigravity', 'gemini-cli', 'iflow'];
|
||||
const CALLBACK_PROVIDER_MAP: Partial<Record<OAuthProvider, string>> = {
|
||||
'gemini-cli': 'gemini'
|
||||
};
|
||||
|
||||
export const oauthApi = {
|
||||
startAuth: (provider: OAuthProvider) =>
|
||||
apiClient.get<OAuthStartResponse>(`/${provider}-auth-url`, {
|
||||
params: WEBUI_SUPPORTED.includes(provider) ? { is_webui: true } : undefined
|
||||
}),
|
||||
startAuth: (provider: OAuthProvider, options?: { projectId?: string }) => {
|
||||
const params: Record<string, string | boolean> = {};
|
||||
if (WEBUI_SUPPORTED.includes(provider)) {
|
||||
params.is_webui = true;
|
||||
}
|
||||
if (provider === 'gemini-cli' && options?.projectId) {
|
||||
params.project_id = options.projectId;
|
||||
}
|
||||
return apiClient.get<OAuthStartResponse>(`/${provider}-auth-url`, {
|
||||
params: Object.keys(params).length ? params : undefined
|
||||
});
|
||||
},
|
||||
|
||||
getAuthStatus: (state: string) =>
|
||||
apiClient.get<{ status: 'ok' | 'wait' | 'error'; error?: string }>(`/get-auth-status`, {
|
||||
params: { state }
|
||||
}),
|
||||
|
||||
submitCallback: (provider: OAuthProvider, redirectUrl: string) => {
|
||||
const callbackProvider = CALLBACK_PROVIDER_MAP[provider] ?? provider;
|
||||
return apiClient.post<OAuthCallbackResponse>('/oauth-callback', {
|
||||
provider: callbackProvider,
|
||||
redirect_url: redirectUrl
|
||||
});
|
||||
},
|
||||
|
||||
/** iFlow cookie 认证 */
|
||||
iflowCookieAuth: (cookie: string) =>
|
||||
apiClient.post<IFlowCookieAuthResponse>('/iflow-auth-url', { cookie })
|
||||
|
||||
Reference in New Issue
Block a user