"use client"; import { SettingsContainer, SettingsSection, SettingsSectionBody, SettingsSectionDescription, SettingsSectionForm, SettingsSectionGrid, SettingsSectionHeader, SettingsSectionTitle } from "@app/components/Settings"; import { Form, FormControl, FormDescription, FormField, FormItem, FormLabel, FormMessage } from "@app/components/ui/form"; import { z } from "zod"; import { useForm } from "react-hook-form"; import { zodResolver } from "@hookform/resolvers/zod"; import { Input } from "@app/components/ui/input"; import { Checkbox } from "@app/components/ui/checkbox"; import { Alert, AlertDescription, AlertTitle } from "@app/components/ui/alert"; import { InfoIcon, ExternalLink } from "lucide-react"; import { StrategySelect } from "@app/components/StrategySelect"; import { SwitchInput } from "@app/components/SwitchInput"; import { Badge } from "@app/components/ui/badge"; import { useTranslations } from "next-intl"; type CreateIdpFormValues = { name: string; type: "oidc"; clientId: string; clientSecret: string; authUrl: string; tokenUrl: string; identifierPath: string; emailPath?: string; namePath?: string; scopes: string; autoProvision: boolean; }; type IdpCreateWizardProps = { onSubmit: (data: CreateIdpFormValues) => void | Promise; defaultValues?: Partial; loading?: boolean; }; export function IdpCreateWizard({ onSubmit, defaultValues, loading = false }: IdpCreateWizardProps) { const t = useTranslations(); const createIdpFormSchema = z.object({ name: z.string().min(2, { message: t("nameMin", { len: 2 }) }), type: z.enum(["oidc"]), clientId: z.string().min(1, { message: t("idpClientIdRequired") }), clientSecret: z .string() .min(1, { message: t("idpClientSecretRequired") }), authUrl: z.url({ message: t("idpErrorAuthUrlInvalid") }), tokenUrl: z.url({ message: t("idpErrorTokenUrlInvalid") }), identifierPath: z.string().min(1, { message: t("idpPathRequired") }), emailPath: z.string().optional(), namePath: z.string().optional(), scopes: z.string().min(1, { message: t("idpScopeRequired") }), autoProvision: z.boolean().default(false) }); interface ProviderTypeOption { id: "oidc"; title: string; description: string; } const providerTypes: ReadonlyArray = [ { id: "oidc", title: "OAuth2/OIDC", description: t("idpOidcDescription") } ]; const form = useForm({ resolver: zodResolver(createIdpFormSchema), defaultValues: { name: "", type: "oidc", clientId: "", clientSecret: "", authUrl: "", tokenUrl: "", identifierPath: "sub", namePath: "name", emailPath: "email", scopes: "openid profile email", autoProvision: false, ...defaultValues } }); const handleSubmit = (data: CreateIdpFormValues) => { onSubmit(data); }; return ( {t("idpTitle")} {t("idpCreateSettingsDescription")}
( {t("name")} {t("idpDisplayName")} )} />
{ form.setValue( "autoProvision", checked ); }} disabled={loading} />
{t("idpAutoProvisionUsersDescription")}
{t("idpType")} {t("idpTypeDescription")} { form.setValue("type", value as "oidc"); }} cols={3} /> {form.watch("type") === "oidc" && ( {t("idpOidcConfigure")} {t("idpOidcConfigureDescription")}
( {t("idpClientId")} {t( "idpClientIdDescription" )} )} /> ( {t("idpClientSecret")} {t( "idpClientSecretDescription" )} )} /> ( {t("idpAuthUrl")} {t("idpAuthUrlDescription")} )} /> ( {t("idpTokenUrl")} {t( "idpTokenUrlDescription" )} )} /> {t("idpOidcConfigureAlert")} {t("idpOidcConfigureAlertDescription")}
{t("idpToken")} {t("idpTokenDescription")}
{t("idpJmespathAbout")} {t("idpJmespathAboutDescription")}{" "} {t( "idpJmespathAboutDescriptionLink" )}{" "} ( {t("idpJmespathLabel")} {t( "idpJmespathLabelDescription" )} )} /> ( {t( "idpJmespathEmailPathOptional" )} {t( "idpJmespathEmailPathOptionalDescription" )} )} /> ( {t( "idpJmespathNamePathOptional" )} {t( "idpJmespathNamePathOptionalDescription" )} )} /> ( {t( "idpOidcConfigureScopes" )} {t( "idpOidcConfigureScopesDescription" )} )} />
)}
); }