/** * OAuth API * Handles OAuth authentication flows with various providers */ import apiClient from './client'; export interface OAuthProvider { name: string; display_name: string; icon: string; } export interface OAuthAuthorizationResponse { authorization_url: string; } export interface OAuthTokenResponse { access: string; refresh: string; user: { id: number; username: string; email: string; name: string; role: string; avatar_url?: string; is_staff: boolean; is_superuser: boolean; business?: number; business_name?: string; business_subdomain?: string; }; } export interface OAuthConnection { id: string; provider: string; provider_user_id: string; email?: string; connected_at: string; } /** * Get list of enabled OAuth providers */ export const getOAuthProviders = async (): Promise => { const response = await apiClient.get<{ providers: OAuthProvider[] }>('/auth/oauth/providers/'); return response.data.providers; }; /** * Initiate OAuth flow - get authorization URL */ export const initiateOAuth = async (provider: string): Promise => { const response = await apiClient.get( `/auth/oauth/${provider}/authorize/` ); return response.data; }; /** * Handle OAuth callback - exchange code for tokens */ export const handleOAuthCallback = async ( provider: string, code: string, state: string ): Promise => { const response = await apiClient.post( `/auth/oauth/${provider}/callback/`, { code, state, } ); return response.data; }; /** * Get user's connected OAuth accounts */ export const getOAuthConnections = async (): Promise => { const response = await apiClient.get<{ connections: OAuthConnection[] }>('/auth/oauth/connections/'); return response.data.connections; }; /** * Disconnect an OAuth account */ export const disconnectOAuth = async (provider: string): Promise => { await apiClient.delete(`/auth/oauth/connections/${provider}/`); };