/* eslint-disable */ // @ts-nocheck import type RealmRepresentation from "@keycloak/keycloak-admin-client/lib/defs/realmRepresentation"; import type { FieldValues } from "react-hook-form"; import { ActionGroup, AlertVariant, Button, ButtonVariant, Divider, FormGroup, PageSection, Popover, Text, TextContent, Title, } from "../../../shared/@patternfly/react-core"; import { QuestionCircleIcon } from "../../../shared/@patternfly/react-icons"; import { ReactNode, useEffect } from "react"; import { FormProvider, useForm, Validate } from "react-hook-form"; import { useTranslation } from "react-i18next"; import { HelpItem, SelectControl, SwitchControl, TextControl, useHelp, } from "../../../shared/keycloak-ui-shared"; import { useAlerts } from "../../../shared/keycloak-ui-shared"; import { FormAccess } from "../../components/form/FormAccess"; import { MultiLineInput } from "../../components/multi-line-input/MultiLineInput"; import { TimeSelectorControl } from "../../components/time-selector/TimeSelectorControl"; import { useRealm } from "../../context/realm-context/RealmContext"; import { convertFormValuesToObject, convertToFormValues } from "../../util"; import useIsFeatureEnabled, { Feature } from "../../utils/useIsFeatureEnabled"; import { useAdminClient } from "../../admin-client"; import "./webauthn-policy.css"; const SIGNATURE_ALGORITHMS = [ "ES256", "ES384", "ES512", "RS256", "RS384", "RS512", "Ed25519", "RS1", ] as const; const ATTESTATION_PREFERENCE = [ "not specified", "none", "indirect", "direct", ] as const; const AUTHENTICATOR_ATTACHMENT = [ "not specified", "platform", "cross-platform", ] as const; const RESIDENT_KEY_OPTIONS = ["not specified", "Yes", "No"] as const; const RESIDENT_KEY_REQUIREMENT = [ "not specified", "required", "preferred", "discouraged", ] as const; const USER_VERIFY = [ "not specified", "required", "preferred", "discouraged", ] as const; const MEDIATION_OPTIONS = [ "conditional", "none", "optional", "required", "silent", ] as const; type WeauthnSelectProps = { name: string; label: string; labelIcon?: string | ReactNode; options: readonly string[]; labelPrefix?: string; isMultiSelect?: boolean; validate?: Validate; }; const WebauthnSelect = ({ name, label, labelIcon, options, labelPrefix, isMultiSelect = false, validate, }: WeauthnSelectProps) => { const { t } = useTranslation(); return ( ({ key: option, value: labelPrefix ? t(`${labelPrefix}.${option}`) : option, }))} /> ); }; type WebauthnPolicyProps = { realm: RealmRepresentation; realmUpdated: (realm: RealmRepresentation) => void; isPasswordLess?: boolean; }; export const WebauthnPolicy = ({ realm, realmUpdated, isPasswordLess = false, }: WebauthnPolicyProps) => { const { adminClient } = useAdminClient(); const { t } = useTranslation(); const { addAlert, addError } = useAlerts(); const { realm: realmName } = useRealm(); const { enabled } = useHelp(); const form = useForm({ mode: "onChange" }); const { setValue, handleSubmit, watch, formState: { isDirty }, } = form; const namePrefix = isPasswordLess ? "webAuthnPolicyPasswordless" : "webAuthnPolicy"; const setupForm = (realm: RealmRepresentation) => convertToFormValues(realm, setValue); useEffect(() => setupForm(realm), []); const onSubmit = async (realm: RealmRepresentation) => { const submittedRealm = convertFormValuesToObject(realm); try { await adminClient.realms.update({ realm: realmName }, submittedRealm); realmUpdated(submittedRealm); setupForm(submittedRealm); addAlert(t("webAuthnUpdateSuccess"), AlertVariant.success); } catch (error) { addError("webAuthnUpdateError", error); } }; const isFeatureEnabled = useIsFeatureEnabled(); const acceptableAAGUIDs = watch(`${namePrefix}AcceptableAaguids`, []); const requireResidentKey = watch( `${namePrefix}RequireResidentKey`, "not specified", ); return ( {enabled && ( {t("webauthnIntro")} )} {isPasswordLess && isFeatureEnabled(Feature.Passkeys) && ( <> {t("passkeys")} {watch(`${namePrefix}PasskeysEnabled`) && ( )} {t("webauthnPasswordlessPolicy")} )} { const hasValidAAGUIDs = acceptableAAGUIDs.some( (guid: string) => guid.trim().length > 0, ); if ( (value === "none" || value === "not specified") && hasValidAAGUIDs ) { return t("acceptableAAGUIDsRequiresAttestation"); } }} /> } options={RESIDENT_KEY_OPTIONS} labelPrefix="residentKey" /> } > } > ); };