| 1 | import type { FlaskBaseResponse } from "@/types/flask.d" |
| 2 | import { HttpClient } from "../httpClient" |
| 3 | |
| 4 | export interface SSOConfigResponse { |
| 5 | sso_enabled: boolean |
| 6 | azure_enabled: boolean |
| 7 | azure_tenant_id: string | null |
| 8 | azure_client_id: string | null |
| 9 | azure_client_secret_set: boolean |
| 10 | azure_redirect_uri: string | null |
| 11 | google_enabled: boolean |
| 12 | google_client_id: string | null |
| 13 | google_client_secret_set: boolean |
| 14 | google_redirect_uri: string | null |
| 15 | cf_enabled: boolean |
| 16 | cf_team_domain: string | null |
| 17 | cf_audience: string | null |
| 18 | } |
| 19 | |
| 20 | export interface SSOConfigUpdate { |
| 21 | sso_enabled: boolean |
| 22 | azure_enabled: boolean |
| 23 | azure_tenant_id?: string | null |
| 24 | azure_client_id?: string | null |
| 25 | azure_client_secret?: string | null |
| 26 | azure_redirect_uri?: string | null |
| 27 | google_enabled: boolean |
| 28 | google_client_id?: string | null |
| 29 | google_client_secret?: string | null |
| 30 | google_redirect_uri?: string | null |
| 31 | cf_enabled: boolean |
| 32 | cf_team_domain?: string | null |
| 33 | cf_audience?: string | null |
| 34 | } |
| 35 | |
| 36 | export interface SSOAllowedEmail { |
| 37 | id: number |
| 38 | email: string |
| 39 | role_id: number |
| 40 | created_at: string |
| 41 | } |
| 42 | |
| 43 | export interface SSOAllowedEmailInput { |
| 44 | email: string |
| 45 | role_id: number |
| 46 | } |
| 47 | |
| 48 | export interface SSOPublicStatus { |
| 49 | sso_enabled: boolean |
| 50 | azure_enabled: boolean |
| 51 | google_enabled: boolean |
| 52 | cf_enabled: boolean |
| 53 | azure_authorization_url: string | null |
| 54 | google_authorization_url: string | null |
| 55 | } |
| 56 | |
| 57 | export interface SSOCloudflareVerifyResponse { |
| 58 | access_token: string |
| 59 | token_type: string |
| 60 | requires_2fa?: boolean |
| 61 | } |
| 62 | |
| 63 | export default { |
| 64 | /** Public — which SSO providers are active */ |
| 65 | getStatus() { |
| 66 | return HttpClient.get<FlaskBaseResponse & SSOPublicStatus>("/auth/sso/status") |
| 67 | }, |
| 68 | |
| 69 | /** Admin — get SSO settings */ |
| 70 | getSettings() { |
| 71 | return HttpClient.get<FlaskBaseResponse & SSOConfigResponse>("/auth/sso/settings") |
| 72 | }, |
| 73 | |
| 74 | /** Admin — update SSO settings */ |
| 75 | updateSettings(payload: SSOConfigUpdate) { |
| 76 | return HttpClient.put<FlaskBaseResponse & SSOConfigResponse>("/auth/sso/settings", payload) |
| 77 | }, |
| 78 | |
| 79 | /** Admin — list allowed emails */ |
| 80 | getAllowedEmails() { |
| 81 | return HttpClient.get<FlaskBaseResponse & { emails: SSOAllowedEmail[] }>("/auth/sso/allowed-emails") |
| 82 | }, |
| 83 | |
| 84 | /** Admin — add allowed email */ |
| 85 | addAllowedEmail(payload: SSOAllowedEmailInput) { |
| 86 | return HttpClient.post<FlaskBaseResponse & { id: number }>("/auth/sso/allowed-emails", payload) |
| 87 | }, |
| 88 | |
| 89 | /** Admin — remove allowed email */ |
| 90 | removeAllowedEmail(emailId: number) { |
| 91 | return HttpClient.delete<FlaskBaseResponse>(`/auth/sso/allowed-emails/${emailId}`) |
| 92 | }, |
| 93 | |
| 94 | /** Cloudflare Access — verify JWT from header */ |
| 95 | cloudflareVerify() { |
| 96 | return HttpClient.post<FlaskBaseResponse & SSOCloudflareVerifyResponse>("/auth/sso/cloudflare/verify") |
| 97 | } |
| 98 | } |