{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "security-06",
  "description": "A single sign-on connection with details to copy into your identity provider, verified domains, and a switch to require it.",
  "registryDependencies": [
    "button",
    "input",
    "https://www.dashboardblocks.com/r/radix/option-select.json",
    "switch",
    "textarea",
    "https://www.dashboardblocks.com/r/radix/block-state.json",
    "https://www.dashboardblocks.com/r/radix/settings.json"
  ],
  "files": [
    {
      "path": "registry/components/dashboardblocks/security/security-06.tsx",
      "content": "'use client'\n\nimport {\n  BlockStateProvider,\n  BlockStateRows,\n  type BlockStateProps,\n  getBlockState,\n} from '@/registry/components/dashboardblocks/block-state'\nimport { OptionSelect } from '@/registry/components/dashboardblocks/option-select'\nimport {\n  type ConnectionStatus,\n  ConnectionStatusLabel,\n  CopyButton,\n  SettingsRow,\n} from '@/registry/components/dashboardblocks/settings'\nimport { type FormEvent, startTransition, useId, useState } from 'react'\n\nimport { Button } from '@/components/ui/button'\nimport { Input } from '@/components/ui/input'\nimport { Switch } from '@/components/ui/switch'\nimport { Textarea } from '@/components/ui/textarea'\n\ninterface SsoConnection {\n  /** The identity provider's signing certificate, in PEM. */\n  certificate: string\n  issuer: string\n  provider: string\n  signInUrl: string\n}\n\ninterface SsoDomain {\n  domain: string\n  id: string\n  txtRecord: string\n  verified: boolean\n}\n\ninterface Security6Props extends BlockStateProps {\n  acsUrl: string\n  /** Leave out to show the empty state. */\n  connection?: SsoConnection\n  /** @default 'disconnected' */\n  connectionStatus?: ConnectionStatus\n  description: string\n  domains?: SsoDomain[]\n  enforced?: boolean\n  entityId: string\n  onEnforcedChange?: (enforced: boolean) => void\n  onSave?: (connection: SsoConnection) => void\n  onVerifyDomain?: (id: string) => boolean | Promise<boolean>\n  providers: string[]\n  title: string\n}\n\ninterface SsoSettingsProps extends Omit<Security6Props, 'connection' | 'status'> {\n  connection: SsoConnection\n}\n\nconst exampleProps: Security6Props = {\n  acsUrl: 'https://app.acme.co/sso/saml/acs',\n  connection: {\n    certificate:\n      '-----BEGIN CERTIFICATE-----\\nMIIDpDCCAoygAwIBAgIGAY…\\n-----END CERTIFICATE-----',\n    issuer: 'http://www.okta.com/exk8f2m1q9ZrT4bH5d7',\n    provider: 'Okta',\n    signInUrl: 'https://acme.okta.com/app/acme_analytics/exk8f2m1q9/sso/saml',\n  },\n  description: 'Let people sign in with your company’s identity provider over SAML.',\n  domains: [\n    { domain: 'acme.co', id: 'd1', txtRecord: 'acme-verify=5f2c9a71e3', verified: true },\n    {\n      domain: 'acme.io',\n      id: 'd2',\n      txtRecord: 'acme-verify=b81d04c6fa',\n      verified: false,\n    },\n  ],\n  enforced: false,\n  entityId: 'https://app.acme.co/sso/saml/metadata/ws_4f9a',\n  providers: ['Okta', 'Microsoft Entra ID', 'Google Workspace', 'OneLogin', 'Other SAML'],\n  connectionStatus: 'connected',\n  title: 'Single sign-on',\n}\n\nfunction SsoSettings(props: SsoSettingsProps) {\n  const {\n    acsUrl,\n    connectionStatus: status = 'disconnected',\n    description,\n    entityId,\n    onEnforcedChange,\n    onSave,\n    onVerifyDomain,\n    providers,\n    title,\n  } = props\n  const id = useId()\n  const [saved, setSaved] = useState(props.connection)\n  const [draft, setDraft] = useState(props.connection)\n  const [domains, setDomains] = useState(props.domains ?? [])\n  const [enforced, setEnforced] = useState(props.enforced ?? false)\n  const [checking, setChecking] = useState<string | null>(null)\n  const [notFound, setNotFound] = useState<string | null>(null)\n  const [error, setError] = useState<string | null>(null)\n\n  const dirty = (Object.keys(draft) as (keyof SsoConnection)[]).some(\n    (key) => draft[key] !== saved[key],\n  )\n  const verified = domains.filter((domain) => domain.verified)\n  const canEnforce = status === 'connected' && verified.length > 0\n\n  const save = (event: FormEvent<HTMLFormElement>) => {\n    event.preventDefault()\n    if (!/^https:\\/\\//.test(draft.signInUrl.trim()))\n      return setError('The sign-in URL must start with https://.')\n    if (!draft.issuer.trim() || !draft.certificate.trim())\n      return setError('Add the issuer and certificate from your identity provider.')\n    const next = {\n      ...draft,\n      certificate: draft.certificate.trim(),\n      issuer: draft.issuer.trim(),\n      signInUrl: draft.signInUrl.trim(),\n    }\n    setError(null)\n    setDraft(next)\n    setSaved(next)\n    onSave?.(next)\n  }\n\n  const verify = async (domain: SsoDomain) => {\n    setChecking(domain.id)\n    const ok = onVerifyDomain ? await onVerifyDomain(domain.id) : true\n    startTransition(() => {\n      setChecking(null)\n      setNotFound(ok ? null : domain.id)\n      if (ok) {\n        setDomains((current) =>\n          current.map((item) =>\n            item.id === domain.id ? { ...item, verified: true } : item,\n          ),\n        )\n      }\n    })\n  }\n\n  const field = (key: keyof SsoConnection, value: string) =>\n    setDraft((current) => ({ ...current, [key]: value }))\n\n  return (\n    <section className='@container flex flex-col gap-4'>\n      <header className='flex items-start justify-between gap-3'>\n        <div className='flex min-w-0 flex-col gap-0.5'>\n          <h2 className='font-semibold tracking-tight'>{title}</h2>\n          <p className='text-muted-foreground text-sm'>{description}</p>\n        </div>\n        <ConnectionStatusLabel className='mt-1' status={status} />\n      </header>\n      <section aria-labelledby={`${id}-sp`} className='flex flex-col gap-3 border-t pt-4'>\n        <h3 id={`${id}-sp`} className='text-sm font-medium'>\n          Add these to your identity provider\n        </h3>\n        {[\n          { label: 'ACS URL', value: acsUrl },\n          { label: 'Entity ID', value: entityId },\n        ].map((item) => (\n          <div key={item.label} className='flex flex-col gap-1'>\n            <span className='text-muted-foreground text-xs'>{item.label}</span>\n            <div className='bg-muted/50 flex items-center gap-1 rounded-md border py-1 pr-1 pl-3'>\n              <code className='min-w-0 flex-1 truncate font-mono text-sm'>\n                {item.value}\n              </code>\n              <CopyButton label={`Copy ${item.label}`} value={item.value} />\n            </div>\n          </div>\n        ))}\n      </section>\n\n      <form\n        method='post'\n        noValidate\n        onSubmit={save}\n        aria-labelledby={`${id}-idp`}\n        className='flex flex-col gap-4 border-t pt-4'\n      >\n        <h3 id={`${id}-idp`} className='text-sm font-medium'>\n          Your identity provider\n        </h3>\n        <div className='grid gap-4 @md:grid-cols-2'>\n          <div className='flex flex-col gap-2'>\n            <label htmlFor={`${id}-provider`} className='text-sm'>\n              Provider\n            </label>\n            <OptionSelect\n              id={`${id}-provider`}\n              className='w-full'\n              value={draft.provider}\n              options={providers.map((provider) => ({\n                label: provider,\n                value: provider,\n              }))}\n              onValueChange={(provider) => field('provider', provider)}\n            />\n          </div>\n          <div className='flex flex-col gap-2'>\n            <label htmlFor={`${id}-issuer`} className='text-sm'>\n              Issuer\n            </label>\n            <Input\n              id={`${id}-issuer`}\n              spellCheck={false}\n              value={draft.issuer}\n              onChange={(event) => field('issuer', event.target.value)}\n            />\n          </div>\n          <div className='flex flex-col gap-2 @md:col-span-2'>\n            <label htmlFor={`${id}-url`} className='text-sm'>\n              Sign-in URL\n            </label>\n            <Input\n              id={`${id}-url`}\n              type='url'\n              spellCheck={false}\n              value={draft.signInUrl}\n              onChange={(event) => field('signInUrl', event.target.value)}\n            />\n          </div>\n          <div className='flex flex-col gap-2 @md:col-span-2'>\n            <label htmlFor={`${id}-certificate`} className='text-sm'>\n              Certificate\n            </label>\n            <Textarea\n              id={`${id}-certificate`}\n              rows={4}\n              spellCheck={false}\n              value={draft.certificate}\n              onChange={(event) => field('certificate', event.target.value)}\n              className='font-mono text-xs'\n            />\n          </div>\n        </div>\n        {error && (\n          <p role='alert' className='text-destructive text-sm'>\n            {error}\n          </p>\n        )}\n        <div className='flex justify-end gap-2'>\n          <Button\n            type='button'\n            variant='ghost'\n            disabled={!dirty}\n            onClick={() => {\n              setDraft(saved)\n              setError(null)\n            }}\n          >\n            Cancel\n          </Button>\n          <Button type='submit' disabled={!dirty}>\n            Save\n          </Button>\n        </div>\n      </form>\n\n      <section\n        aria-labelledby={`${id}-domains`}\n        className='flex flex-col gap-3 border-t pt-4'\n      >\n        <div className='flex flex-col gap-0.5'>\n          <h3 id={`${id}-domains`} className='text-sm font-medium'>\n            Domains\n          </h3>\n          <p className='text-muted-foreground text-sm'>\n            People with an email at a verified domain sign in with SSO.\n          </p>\n        </div>\n        <ul className='flex flex-col divide-y border-t'>\n          {domains.map((domain) => (\n            <li key={domain.id} className='flex flex-col gap-2 py-3'>\n              <div className='flex items-center gap-3'>\n                <span className='min-w-0 flex-1 truncate text-sm font-medium'>\n                  {domain.domain}\n                </span>\n                {domain.verified ? (\n                  <ConnectionStatusLabel status='connected' label='Verified' />\n                ) : (\n                  <>\n                    <ConnectionStatusLabel status='paused' label='Not verified' />\n                    <Button\n                      variant='outline'\n                      size='sm'\n                      disabled={checking === domain.id}\n                      aria-label={`Verify ${domain.domain}`}\n                      onClick={() => void verify(domain)}\n                    >\n                      {checking === domain.id ? 'Checking' : 'Verify'}\n                    </Button>\n                  </>\n                )}\n              </div>\n              {!domain.verified && (\n                <div className='flex flex-col gap-1'>\n                  <span className='text-muted-foreground text-xs'>\n                    Add this TXT record to {domain.domain}’s DNS, then verify.\n                  </span>\n                  <div className='bg-muted/50 flex items-center gap-1 rounded-md border py-1 pr-1 pl-3'>\n                    <code className='min-w-0 flex-1 truncate font-mono text-sm'>\n                      {domain.txtRecord}\n                    </code>\n                    <CopyButton\n                      label={`Copy TXT record for ${domain.domain}`}\n                      value={domain.txtRecord}\n                    />\n                  </div>\n                  {notFound === domain.id && (\n                    <p role='alert' className='text-destructive text-xs'>\n                      We couldn’t find the record yet. DNS changes can take up to an hour.\n                    </p>\n                  )}\n                </div>\n              )}\n            </li>\n          ))}\n        </ul>\n      </section>\n\n      <SettingsRow\n        className='border-t pt-4'\n        id={`${id}-enforce`}\n        label='Require SSO'\n        description={\n          canEnforce\n            ? `Everyone at ${verified.map((domain) => domain.domain).join(', ')} must sign in with ${saved.provider}. Owners can still use a password.`\n            : 'Connect your identity provider and verify a domain first.'\n        }\n      >\n        <Switch\n          aria-labelledby={`${id}-enforce`}\n          aria-describedby={`${id}-enforce-description`}\n          checked={enforced && canEnforce}\n          disabled={!canEnforce}\n          onCheckedChange={(next) => {\n            setEnforced(next)\n            onEnforcedChange?.(next)\n          }}\n        />\n      </SettingsRow>\n    </section>\n  )\n}\n\nconst Security6 = (props: Security6Props) => {\n  const { connection, description, errorMessage, status, title } = props\n  const state = getBlockState(status, connection)\n\n  return (\n    <BlockStateProvider errorMessage={errorMessage} state={state}>\n      {state || !connection ? (\n        <section className='@container flex flex-col gap-4'>\n          <header className='flex flex-col gap-0.5'>\n            <h2 className='font-semibold tracking-tight'>{title}</h2>\n            <p className='text-muted-foreground text-sm'>{description}</p>\n          </header>\n          <BlockStateRows className='border-t' rows={4} />\n        </section>\n      ) : (\n        <SsoSettings {...props} connection={connection} />\n      )}\n    </BlockStateProvider>\n  )\n}\n\nexport {\n  Security6,\n  exampleProps as security6ExampleProps,\n  type Security6Props,\n  type SsoConnection,\n  type SsoDomain,\n}\n",
      "type": "registry:component",
      "target": "@components/dashboardblocks/security/security-06.tsx"
    }
  ],
  "meta": {
    "shows": "A single sign-on connection with details to copy into your identity provider, verified domains, and a switch to require it.",
    "size": "half",
    "usedWith": [
      "security-04",
      "team-05",
      "settings-01"
    ],
    "component": "Security6",
    "props": "{ acsUrl: string; connection?: { certificate: string; issuer: string; provider: string; signInUrl: string }; connectionStatus?: \"error\" | \"connected\" | \"disconnected\" | \"importing\" | \"paused\" | \"revoked\"; description: string; domains?: { domain: string; id: string; txtRecord: string; verified: boolean }[]; enforced?: boolean; entityId: string; onEnforcedChange?: (enforced: boolean) => void; onSave?: (connection: { certificate: string; issuer: string; provider: string; signInUrl: string }) => void; onVerifyDomain?: (id: string) => boolean | Promise<boolean>; providers: string[]; title: string; errorMessage?: string; status?: \"loading\" | \"error\" }"
  },
  "type": "registry:component"
}
