mirror of
https://github.com/router-for-me/Cli-Proxy-API-Management-Center.git
synced 2026-02-03 11:20:50 +08:00
69 lines
1.8 KiB
TypeScript
69 lines
1.8 KiB
TypeScript
/**
|
|
* OAuth 与设备码登录相关 API
|
|
*/
|
|
|
|
import { apiClient } from './client';
|
|
|
|
export type OAuthProvider =
|
|
| 'codex'
|
|
| 'anthropic'
|
|
| 'antigravity'
|
|
| 'gemini-cli'
|
|
| 'qwen'
|
|
| 'iflow';
|
|
|
|
export interface OAuthStartResponse {
|
|
url: string;
|
|
state?: string;
|
|
}
|
|
|
|
export interface OAuthCallbackResponse {
|
|
status: 'ok';
|
|
}
|
|
|
|
export interface IFlowCookieAuthResponse {
|
|
status: 'ok' | 'error';
|
|
error?: string;
|
|
saved_path?: string;
|
|
email?: string;
|
|
expired?: string;
|
|
type?: string;
|
|
}
|
|
|
|
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, 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 })
|
|
};
|