import { zodResolver } from '@hookform/resolvers/zod' import { useParams } from 'common' import { SubmitHandler, useForm } from 'react-hook-form' import { toast } from 'sonner' import { Button, Dialog, DialogContent, DialogFooter, DialogHeader, DialogSection, DialogTitle, Form, FormControl, FormField, Input, Separator, } from 'ui' import { FormItemLayout } from 'ui-patterns/form/FormItemLayout/FormItemLayout' import * as z from 'zod' import { isValidOidcIssuerUrl } from './ThirdPartyAuthForm.utils' import { ButtonTooltip } from '@/components/ui/ButtonTooltip' import { useCreateThirdPartyAuthIntegrationMutation } from '@/data/third-party-auth/integration-create-mutation' import { getWriteGrantToastMessage, getWriteGrantTooltip, useGrant } from '@/lib/grants' interface CreateCustomOidcIntegrationDialogProps { visible: boolean onClose: () => void } const FORM_ID = 'create-custom-oidc-integration-form' const FormSchema = z.object({ issuerUrl: z .string() .trim() .min(1, 'Issuer URL is required') .refine(isValidOidcIssuerUrl, 'Enter an HTTPS URL without a query string or fragment'), }) type FormValues = z.infer const defaultValues: FormValues = { issuerUrl: '' } export const CreateCustomOidcIntegrationDialog = ({ visible, onClose, }: CreateCustomOidcIntegrationDialogProps) => { const { ref: projectRef } = useParams() const createGrant = useGrant('POST /v1/projects/{ref}/config/auth/third-party-auth', { projectRef, }) const form = useForm({ resolver: zodResolver(FormSchema), defaultValues, }) const handleClose = () => { form.reset(defaultValues) onClose() } const { mutate: createAuthIntegration, isPending } = useCreateThirdPartyAuthIntegrationMutation({ onSuccess: () => { toast.success('Custom OIDC provider added') handleClose() }, }) const onSubmit: SubmitHandler = (values) => { if (!createGrant.grant) { toast.error( getWriteGrantToastMessage(createGrant.status, 'add', 'third-party auth integrations') ) return } createAuthIntegration({ projectRef: projectRef!, grant: createGrant.grant, oidcIssuerUrl: values.issuerUrl, }) } return ( !open && handleClose()}> Add custom OIDC provider

Accept JWTs from any OpenID Connect (OIDC) provider.

( Signing keys are found at the issuer's{' '} /.well-known/openid-configuration } > )} />
Add provider
) }