UNPKG

@keycloakify/keycloak-admin-ui

Version:
58 lines 14.6 kB
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime"; import { FormPanel, HelpItem, KeycloakSelect, SelectVariant, } from "../ui-shared"; import { ActionGroup, Button, FormGroup, FormHelperText, HelperText, HelperTextItem, NumberInput, PageSection, SelectOption, Switch, Text, TextInput, TextVariants, } from "@patternfly/react-core"; import { useEffect, useState } from "react"; import { Controller, useForm, useWatch } from "react-hook-form"; import { useTranslation } from "react-i18next"; import { FormAccess } from "../components/form/FormAccess"; import { TimeSelector, toHumanFormat, } from "../components/time-selector/TimeSelector"; import { useServerInfo } from "../context/server-info/ServerInfoProvider"; import { useWhoAmI } from "../context/whoami/WhoAmI"; import { beerify, convertToFormValues, sortProviders } from "../util"; import useIsFeatureEnabled, { Feature } from "../utils/useIsFeatureEnabled"; import "./realm-settings-section.css"; export const RealmSettingsTokensTab = ({ realm, reset, save, }) => { const { t } = useTranslation(); const serverInfo = useServerInfo(); const isFeatureEnabled = useIsFeatureEnabled(); const { whoAmI } = useWhoAmI(); const [defaultSigAlgDrpdwnIsOpen, setDefaultSigAlgDrpdwnOpen] = useState(false); const defaultSigAlgOptions = sortProviders(serverInfo.providers["signature"].providers); const form = useForm(); const { setValue, control } = form; const offlineSessionMaxEnabled = useWatch({ control, name: "offlineSessionMaxLifespanEnabled", defaultValue: realm.offlineSessionMaxLifespanEnabled, }); const ssoSessionIdleTimeout = useWatch({ control, name: "ssoSessionIdleTimeout", defaultValue: 36000, }); const revokeRefreshToken = useWatch({ control, name: "revokeRefreshToken", defaultValue: false, }); useEffect(() => { convertToFormValues(realm, setValue); }, []); return (_jsxs(PageSection, { variant: "light", children: [_jsx(FormPanel, { title: t("general"), className: "kc-sso-session-template", children: _jsxs(FormAccess, { isHorizontal: true, role: "manage-realm", onSubmit: form.handleSubmit(save), children: [_jsx(FormGroup, { label: t("defaultSigAlg"), fieldId: "kc-default-signature-algorithm", labelIcon: _jsx(HelpItem, { helpText: t("defaultSigAlgHelp"), fieldLabelId: "algorithm" }), children: _jsx(Controller, { name: "defaultSignatureAlgorithm", defaultValue: "RS256", control: form.control, render: ({ field }) => { var _a; return (_jsx(KeycloakSelect, { toggleId: "kc-default-sig-alg", onToggle: () => setDefaultSigAlgDrpdwnOpen(!defaultSigAlgDrpdwnIsOpen), onSelect: (value) => { field.onChange(value.toString()); setDefaultSigAlgDrpdwnOpen(false); }, selections: (_a = field.value) === null || _a === void 0 ? void 0 : _a.toString(), variant: SelectVariant.single, "aria-label": t("defaultSigAlg"), isOpen: defaultSigAlgDrpdwnIsOpen, "data-testid": "select-default-sig-alg", children: defaultSigAlgOptions.map((p, idx) => (_jsx(SelectOption, { selected: p === field.value, value: p, children: p }, `default-sig-alg-${idx}`))) })); } }) }), isFeatureEnabled(Feature.DeviceFlow) && (_jsxs(_Fragment, { children: [_jsx(FormGroup, { label: t("oAuthDeviceCodeLifespan"), fieldId: "oAuthDeviceCodeLifespan", labelIcon: _jsx(HelpItem, { helpText: t("oAuthDeviceCodeLifespanHelp"), fieldLabelId: "oAuthDeviceCodeLifespan" }), children: _jsx(Controller, { name: "oauth2DeviceCodeLifespan", defaultValue: 0, control: form.control, render: ({ field }) => (_jsx(TimeSelector, { id: "oAuthDeviceCodeLifespan", "data-testid": "oAuthDeviceCodeLifespan", value: field.value || 0, onChange: field.onChange, units: ["minute", "hour", "day"] })) }) }), _jsx(FormGroup, { label: t("oAuthDevicePollingInterval"), fieldId: "oAuthDevicePollingInterval", labelIcon: _jsx(HelpItem, { helpText: t("oAuthDevicePollingIntervalHelp"), fieldLabelId: "oAuthDevicePollingInterval" }), children: _jsx(Controller, { name: "oauth2DevicePollingInterval", defaultValue: 0, control: form.control, render: ({ field }) => (_jsx(NumberInput, { id: "oAuthDevicePollingInterval", value: field.value, min: 0, onPlus: () => field.onChange(Number(field === null || field === void 0 ? void 0 : field.value) + 1), onMinus: () => field.onChange(Number(field === null || field === void 0 ? void 0 : field.value) > 0 ? Number(field === null || field === void 0 ? void 0 : field.value) - 1 : 0), onChange: (event) => { const newValue = Number(event.currentTarget.value); field.onChange(!isNaN(newValue) ? newValue : 0); }, placeholder: t("oAuthDevicePollingInterval") })) }) }), _jsx(FormGroup, { label: t("shortVerificationUri"), fieldId: "shortVerificationUri", labelIcon: _jsx(HelpItem, { helpText: t("shortVerificationUriTooltipHelp"), fieldLabelId: "shortVerificationUri" }), children: _jsx(TextInput, { id: "shortVerificationUri", placeholder: t("shortVerificationUri"), ...form.register("attributes.shortVerificationUri") }) }), _jsx(FormGroup, { label: t("parRequestUriLifespan"), fieldId: "parRequestUriLifespan", labelIcon: _jsx(HelpItem, { helpText: t("parRequestUriLifespanHelp"), fieldLabelId: "parRequestUriLifespan" }), children: _jsx(Controller, { name: "attributes.parRequestUriLifespan", control: form.control, render: ({ field }) => (_jsx(TimeSelector, { id: "parRequestUriLifespan", className: "par-request-uri-lifespan", "data-testid": "par-request-uri-lifespan-input", "aria-label": "par-request-uri-lifespan", value: field.value, onChange: field.onChange })) }) })] }))] }) }), _jsx(FormPanel, { title: t("refreshTokens"), className: "kc-client-session-template", children: _jsxs(FormAccess, { isHorizontal: true, role: "manage-realm", className: "pf-v5-u-mt-lg", onSubmit: form.handleSubmit(save), children: [_jsx(FormGroup, { hasNoPaddingTop: true, label: t("revokeRefreshToken"), fieldId: "kc-revoke-refresh-token", labelIcon: _jsx(HelpItem, { helpText: t("revokeRefreshTokenHelp"), fieldLabelId: "revokeRefreshToken" }), children: _jsx(Controller, { name: "revokeRefreshToken", control: form.control, defaultValue: false, render: ({ field }) => (_jsx(Switch, { id: "kc-revoke-refresh-token", "data-testid": "revoke-refresh-token-switch", "aria-label": t("revokeRefreshToken"), label: t("enabled"), labelOff: t("disabled"), isChecked: field.value, onChange: field.onChange })) }) }), revokeRefreshToken && (_jsx(FormGroup, { label: t("refreshTokenMaxReuse"), labelIcon: _jsx(HelpItem, { helpText: t("refreshTokenMaxReuseHelp"), fieldLabelId: "refreshTokenMaxReuse" }), fieldId: "refreshTokenMaxReuse", children: _jsx(Controller, { name: "refreshTokenMaxReuse", defaultValue: 0, control: form.control, render: ({ field }) => (_jsx(NumberInput, { type: "text", id: "refreshTokenMaxReuseMs", value: field.value, onPlus: () => field.onChange(field.value + 1), onMinus: () => field.onChange(field.value - 1), onChange: (event) => field.onChange(Number(event.target.value)) })) }) }))] }) }), _jsx(FormPanel, { title: t("accessTokens"), className: "kc-offline-session-template", children: _jsxs(FormAccess, { isHorizontal: true, role: "manage-realm", className: "pf-v5-u-mt-lg", onSubmit: form.handleSubmit(save), children: [_jsxs(FormGroup, { label: t("accessTokenLifespan"), fieldId: "accessTokenLifespan", labelIcon: _jsx(HelpItem, { helpText: t("accessTokenLifespanHelp"), fieldLabelId: "accessTokenLifespan" }), children: [_jsx(Controller, { name: "accessTokenLifespan", control: form.control, render: ({ field }) => (_jsx(TimeSelector, { validated: field.value > ssoSessionIdleTimeout ? "warning" : "default", className: "kc-access-token-lifespan", "data-testid": "access-token-lifespan-input", "aria-label": "access-token-lifespan", value: field.value, onChange: field.onChange, units: ["minute", "hour", "day"] })) }), _jsx(FormHelperText, { children: _jsx(HelperText, { children: _jsx(HelperTextItem, { children: t("recommendedSsoTimeout", { time: toHumanFormat(ssoSessionIdleTimeout, whoAmI.getLocale()), }) }) }) })] }), _jsx(FormGroup, { label: t("accessTokenLifespanImplicitFlow"), fieldId: "accessTokenLifespanImplicitFlow", labelIcon: _jsx(HelpItem, { helpText: t("accessTokenLifespanImplicitFlow"), fieldLabelId: "accessTokenLifespanImplicitFlow" }), children: _jsx(Controller, { name: "accessTokenLifespanForImplicitFlow", control: form.control, render: ({ field }) => (_jsx(TimeSelector, { className: "kc-access-token-lifespan-implicit", "data-testid": "access-token-lifespan-implicit-input", value: field.value, onChange: field.onChange, units: ["minute", "hour", "day"] })) }) }), _jsx(FormGroup, { label: t("clientLoginTimeout"), fieldId: "clientLoginTimeout", labelIcon: _jsx(HelpItem, { helpText: t("clientLoginTimeoutHelp"), fieldLabelId: "clientLoginTimeout" }), children: _jsx(Controller, { name: "accessCodeLifespan", control: form.control, render: ({ field }) => (_jsx(TimeSelector, { className: "kc-client-login-timeout", "data-testid": "client-login-timeout-input", "aria-label": "client-login-timeout", value: field.value, onChange: field.onChange, units: ["minute", "hour", "day"] })) }) }), offlineSessionMaxEnabled && (_jsx(FormGroup, { label: t("offlineSessionMax"), fieldId: "offlineSessionMax", id: "offline-session-max-label", labelIcon: _jsx(HelpItem, { helpText: t("offlineSessionMaxHelp"), fieldLabelId: "offlineSessionMax" }), children: _jsx(Controller, { name: "offlineSessionMaxLifespan", control: form.control, render: ({ field }) => (_jsx(TimeSelector, { className: "kc-offline-session-max", "data-testid": "offline-session-max-input", value: field.value, onChange: field.onChange, units: ["minute", "hour", "day"] })) }) }))] }) }), _jsx(FormPanel, { className: "kc-login-settings-template", title: t("actionTokens"), children: _jsxs(FormAccess, { isHorizontal: true, role: "manage-realm", className: "pf-v5-u-mt-lg", onSubmit: form.handleSubmit(save), children: [_jsx(FormGroup, { label: t("userInitiatedActionLifespan"), id: "kc-user-initiated-action-lifespan", fieldId: "userInitiatedActionLifespan", labelIcon: _jsx(HelpItem, { helpText: t("userInitiatedActionLifespanHelp"), fieldLabelId: "userInitiatedActionLifespan" }), children: _jsx(Controller, { name: "actionTokenGeneratedByUserLifespan", control: form.control, render: ({ field }) => (_jsx(TimeSelector, { className: "kc-user-initiated-action-lifespan", "data-testid": "user-initiated-action-lifespan", "aria-label": "user-initiated-action-lifespan", value: field.value, onChange: field.onChange, units: ["minute", "hour", "day"] })) }) }), _jsx(FormGroup, { label: t("defaultAdminInitiated"), fieldId: "defaultAdminInitiated", id: "default-admin-initiated-label", labelIcon: _jsx(HelpItem, { helpText: t("defaultAdminInitiatedActionLifespanHelp"), fieldLabelId: "defaultAdminInitiated" }), children: _jsx(Controller, { name: "actionTokenGeneratedByAdminLifespan", control: form.control, render: ({ field }) => (_jsx(TimeSelector, { className: "kc-default-admin-initiated", "data-testid": "default-admin-initated-input", "aria-label": "default-admin-initated-input", value: field.value, onChange: field.onChange, units: ["minute", "hour", "day"] })) }) }), _jsx(Text, { className: "kc-override-action-tokens-subtitle", component: TextVariants.h1, children: t("overrideActionTokens") }), _jsx(FormGroup, { label: t("emailVerification"), fieldId: "emailVerification", id: "email-verification", labelIcon: _jsx(HelpItem, { helpText: t("emailVerificationHelp"), fieldLabelId: "emailVerification" }), children: _jsx(Controller, { name: `attributes.${beerify("actionTokenGeneratedByUserLifespan.verify-email")}`, defaultValue: "", control: form.control, render: ({ field }) => (_jsx(TimeSelector, { className: "kc-email-verification", "data-testid": "email-verification-input", value: field.value, onChange: (value) => field.onChange(value.toString()), units: ["minute", "hour", "day"] })) }) }), _jsx(FormGroup, { label: t("idpAccountEmailVerification"), fieldId: "idpAccountEmailVerification", id: "idp-acct-label", labelIcon: _jsx(HelpItem, { helpText: t("idpAccountEmailVerificationHelp"), fieldLabelId: "idpAccountEmailVerification" }), children: _jsx(Controller, { name: `attributes.${beerify("actionTokenGeneratedByUserLifespan.idp-verify-account-via-email")}`, defaultValue: "", control: form.control, render: ({ field }) => (_jsx(TimeSelector, { className: "kc-idp-email-verification", "data-testid": "idp-email-verification-input", value: field.value, onChange: field.onChange, units: ["minute", "hour", "day"] })) }) }), _jsx(FormGroup, { label: t("forgotPassword"), fieldId: "forgotPassword", id: "forgot-password-label", labelIcon: _jsx(HelpItem, { helpText: t("forgotPasswordHelp"), fieldLabelId: "forgotPassword" }), children: _jsx(Controller, { name: `attributes.${beerify("actionTokenGeneratedByUserLifespan.reset-credentials")}`, defaultValue: "", control: form.control, render: ({ field }) => (_jsx(TimeSelector, { className: "kc-forgot-pw", "data-testid": "forgot-pw-input", value: field.value, onChange: field.onChange, units: ["minute", "hour", "day"] })) }) }), _jsx(FormGroup, { label: t("executeActions"), fieldId: "executeActions", id: "execute-actions", labelIcon: _jsx(HelpItem, { helpText: t("executeActionsHelp"), fieldLabelId: "executeActions" }), children: _jsx(Controller, { name: `attributes.${beerify("actionTokenGeneratedByUserLifespan.execute-actions")}`, defaultValue: "", control: form.control, render: ({ field }) => (_jsx(TimeSelector, { className: "kc-execute-actions", "data-testid": "execute-actions-input", value: field.value, onChange: field.onChange, units: ["minute", "hour", "day"] })) }) }), _jsxs(ActionGroup, { children: [_jsx(Button, { variant: "primary", type: "submit", "data-testid": "tokens-tab-save", isDisabled: !form.formState.isDirty, children: t("save") }), _jsx(Button, { variant: "link", onClick: reset, children: t("revert") })] })] }) })] })); }; //# sourceMappingURL=TokensTab.js.map