feat(oauth): add callback URL submission and require Gemini CLI project ID

This commit is contained in:
Supra4E8C
2025-12-19 18:04:14 +08:00
parent ddbd7d00bd
commit 39d86d133a
5 changed files with 236 additions and 61 deletions

View File

@@ -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 })