UNPKG

@keycloakify/keycloak-admin-ui

Version:
87 lines 6.81 kB
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime"; import { ActionGroup, AlertVariant, Button, ButtonVariant, FormGroup, PageSection, Popover, Text, TextContent, } from "@patternfly/react-core"; import { QuestionCircleIcon } from "@patternfly/react-icons"; import { useEffect } from "react"; import { FormProvider, useForm } from "react-hook-form"; import { useTranslation } from "react-i18next"; import { HelpItem, SelectControl, SwitchControl, TextControl, useHelp, } from "../../ui-shared"; import { useAlerts } from "../../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 { useAdminClient } from "../../admin-client"; import "./webauthn-policy.css"; const SIGNATURE_ALGORITHMS = [ "ES256", "ES384", "ES512", "RS256", "RS384", "RS512", "Ed25519", "RS1", ]; const ATTESTATION_PREFERENCE = [ "not specified", "none", "indirect", "direct", ]; const AUTHENTICATOR_ATTACHMENT = [ "not specified", "platform", "cross-platform", ]; const RESIDENT_KEY_OPTIONS = ["not specified", "Yes", "No"]; const USER_VERIFY = [ "not specified", "required", "preferred", "discouraged", ]; const WebauthnSelect = ({ name, label, options, labelPrefix, isMultiSelect = false, }) => { const { t } = useTranslation(); return (_jsx(SelectControl, { name: name, label: t(label), variant: isMultiSelect ? "typeaheadMulti" : "single", controller: { defaultValue: options[0] }, options: options.map((option) => ({ key: option, value: labelPrefix ? t(`${labelPrefix}.${option}`) : option, })) })); }; export const WebauthnPolicy = ({ realm, realmUpdated, isPasswordLess = false, }) => { 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, formState: { isDirty }, } = form; const namePrefix = isPasswordLess ? "webAuthnPolicyPasswordless" : "webAuthnPolicy"; const setupForm = (realm) => convertToFormValues(realm, setValue); useEffect(() => setupForm(realm), []); const onSubmit = async (realm) => { 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); } }; return (_jsxs(PageSection, { variant: "light", children: [enabled && (_jsx(Popover, { bodyContent: t(`${namePrefix}FormHelp`), children: _jsx(TextContent, { className: "keycloak__section_intro__help", children: _jsxs(Text, { children: [_jsx(QuestionCircleIcon, {}), " ", t("webauthnIntro")] }) }) })), _jsxs(FormAccess, { role: "manage-realm", isHorizontal: true, onSubmit: handleSubmit(onSubmit), className: "keycloak__webauthn_policies_authentication__form", children: [_jsxs(FormProvider, { ...form, children: [_jsx(TextControl, { name: `${namePrefix}RpEntityName`, label: t("webAuthnPolicyRpEntityName"), labelIcon: t("webAuthnPolicyRpEntityNameHelp"), rules: { required: { value: true, message: t("required") } } }), _jsx(WebauthnSelect, { name: `${namePrefix}SignatureAlgorithms`, label: "webAuthnPolicySignatureAlgorithms", options: SIGNATURE_ALGORITHMS, isMultiSelect: true }), _jsx(TextControl, { name: `${namePrefix}RpId`, label: t("webAuthnPolicyRpId"), labelIcon: t("webAuthnPolicyRpIdHelp") }), _jsx(WebauthnSelect, { name: `${namePrefix}AttestationConveyancePreference`, label: "webAuthnPolicyAttestationConveyancePreference", options: ATTESTATION_PREFERENCE, labelPrefix: "attestationPreference" }), _jsx(WebauthnSelect, { name: `${namePrefix}AuthenticatorAttachment`, label: "webAuthnPolicyAuthenticatorAttachment", options: AUTHENTICATOR_ATTACHMENT, labelPrefix: "authenticatorAttachment" }), _jsx(WebauthnSelect, { name: `${namePrefix}RequireResidentKey`, label: "webAuthnPolicyRequireResidentKey", options: RESIDENT_KEY_OPTIONS, labelPrefix: "residentKey" }), _jsx(WebauthnSelect, { name: `${namePrefix}UserVerificationRequirement`, label: "webAuthnPolicyUserVerificationRequirement", options: USER_VERIFY, labelPrefix: "userVerify" }), _jsx(TimeSelectorControl, { name: `${namePrefix}CreateTimeout`, label: t("webAuthnPolicyCreateTimeout"), labelIcon: t("otpPolicyPeriodHelp"), units: ["second", "minute", "hour"], controller: { defaultValue: 0, rules: { min: 0, max: { value: 31536, message: t("webAuthnPolicyCreateTimeoutHint"), }, }, } }), _jsx(SwitchControl, { name: `${namePrefix}AvoidSameAuthenticatorRegister`, label: t("webAuthnPolicyAvoidSameAuthenticatorRegister"), labelIcon: t("webAuthnPolicyAvoidSameAuthenticatorRegisterHelp"), labelOn: t("on"), labelOff: t("off") }), _jsx(FormGroup, { label: t("webAuthnPolicyAcceptableAaguids"), fieldId: "webAuthnPolicyAcceptableAaguids", labelIcon: _jsx(HelpItem, { helpText: t("webAuthnPolicyAcceptableAaguidsHelp"), fieldLabelId: "webAuthnPolicyAcceptableAaguids" }), children: _jsx(MultiLineInput, { name: `${namePrefix}AcceptableAaguids`, "aria-label": t("webAuthnPolicyAcceptableAaguids"), addButtonLabel: "addAaguids" }) }), _jsx(FormGroup, { label: t("webAuthnPolicyExtraOrigins"), fieldId: "webAuthnPolicyExtraOrigins", labelIcon: _jsx(HelpItem, { helpText: t("webAuthnPolicyExtraOriginsHelp"), fieldLabelId: "webAuthnPolicyExtraOrigins" }), children: _jsx(MultiLineInput, { name: `${namePrefix}ExtraOrigins`, "aria-label": t("webAuthnPolicyExtraOrigins"), addButtonLabel: "addOrigins" }) })] }), _jsxs(ActionGroup, { children: [_jsx(Button, { "data-testid": "save", variant: "primary", type: "submit", isDisabled: !isDirty, children: t("save") }), _jsx(Button, { "data-testid": "reload", variant: ButtonVariant.link, onClick: () => setupForm(realm), children: t("reload") })] })] })] })); }; //# sourceMappingURL=WebauthnPolicy.js.map