/* eslint-disable */ // @ts-nocheck import type RealmRepresentation from "@keycloak/keycloak-admin-client/lib/defs/realmRepresentation"; import { HelpItem, KeycloakSelect, SelectVariant, ScrollForm, useAlerts, SelectControl, NumberControl, } from "../../shared/keycloak-ui-shared"; import { AlertVariant, FormGroup, FormHelperText, HelperText, HelperTextItem, NumberInput, SelectOption, Switch, Text, TextInput, TextVariants, } from "../../shared/@patternfly/react-core"; import { useState } from "react"; import { Controller, useFormContext, useWatch } from "react-hook-form"; import { useTranslation } from "react-i18next"; import { FormAccess } from "../components/form/FormAccess"; import { FixedButtonsGroup } from "../components/form/FixedButtonGroup"; import { DefaultSwitchControl } from "../components/SwitchControl"; import { convertAttributeNameToForm } from "../util"; import { TimeSelector, toHumanFormat, } from "../components/time-selector/TimeSelector"; import { TimeSelectorControl } from "../components/time-selector/TimeSelectorControl"; import { useServerInfo } from "../context/server-info/ServerInfoProvider"; import { useWhoAmI } from "../context/whoami/WhoAmI"; import { beerify, sortProviders } from "../util"; import useIsFeatureEnabled, { Feature } from "../utils/useIsFeatureEnabled"; import "./realm-settings-section.css"; type RealmSettingsTokensTabProps = { realm: RealmRepresentation; save: (realm: RealmRepresentation) => void; }; export const RealmSettingsTokensTab = ({ realm, save, }: RealmSettingsTokensTabProps) => { const { t } = useTranslation(); const { addAlert } = useAlerts(); const serverInfo = useServerInfo(); const isFeatureEnabled = useIsFeatureEnabled(); const { whoAmI } = useWhoAmI(); const openId4vciEnabled = isFeatureEnabled(Feature.OpenId4VCI) && realm.verifiableCredentialsEnabled; const [defaultSigAlgDrpdwnIsOpen, setDefaultSigAlgDrpdwnOpen] = useState(false); const defaultSigAlgOptions = sortProviders( serverInfo.providers!["signature"].providers, ); const asymmetricSigAlgOptions = serverInfo.cryptoInfo?.clientSignatureAsymmetricAlgorithms ?? []; const { control, register, reset, formState, handleSubmit } = useFormContext(); const credentialOfferLifespanDefaultValue = realm.attributes?.["credentialOfferLifespanS"] ?? 300; // Show a global error notification if validation fails const onError = () => { addAlert(t("oid4vciFormValidationError"), AlertVariant.danger); }; 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, }); const requestEncryptionRequired = useWatch({ control, name: convertAttributeNameToForm( "attributes.oid4vci.request.encryption.required", ), defaultValue: realm.attributes?.["oid4vci.request.encryption.required"], }); const strategy = useWatch({ control, name: convertAttributeNameToForm("attributes.oid4vci.time.claims.strategy"), defaultValue: realm.attributes?.["oid4vci.time.claims.strategy"] ?? "off", }); const sections = [ { title: t("general"), panel: ( } > ( setDefaultSigAlgDrpdwnOpen(!defaultSigAlgDrpdwnIsOpen) } onSelect={(value) => { field.onChange(value.toString()); setDefaultSigAlgDrpdwnOpen(false); }} selections={field.value?.toString()} variant={SelectVariant.single} aria-label={t("defaultSigAlg")} isOpen={defaultSigAlgDrpdwnIsOpen} data-testid="select-default-sig-alg" > {defaultSigAlgOptions!.map((p, idx) => ( {p} ))} )} /> {isFeatureEnabled(Feature.DeviceFlow) && ( <> } > ( )} /> } > ( field.onChange(Number(field.value) + 1)} onMinus={() => field.onChange( Number(field.value) > 0 ? Number(field.value) - 1 : 0, ) } onChange={(event) => { const newValue = Number(event.currentTarget.value); field.onChange(!isNaN(newValue) ? newValue : 0); }} placeholder={t("oAuthDevicePollingInterval")} /> )} /> } > } > ( )} /> )} ), }, { title: t("refreshTokens"), panel: ( } > ( )} /> {revokeRefreshToken && ( } fieldId="refreshTokenMaxReuse" > ( field.onChange(field.value! + 1)} onMinus={() => field.onChange(field.value! - 1)} onChange={(event) => field.onChange( Number((event.target as HTMLInputElement).value), ) } /> )} /> )} ), }, { title: t("accessTokens"), panel: ( } > ( 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"]} /> )} /> {t("recommendedSsoTimeout", { time: toHumanFormat(ssoSessionIdleTimeout!, whoAmI.locale), })} } > ( )} /> } > ( )} /> {offlineSessionMaxEnabled && ( } > ( )} /> )} ), }, { title: t("actionTokens"), panel: ( } > ( )} /> } > ( )} /> {t("overrideActionTokens")} } > ( field.onChange(value.toString())} units={["minute", "hour", "day"]} /> )} /> } > ( )} /> } > ( )} /> } > ( )} /> {!openId4vciEnabled && ( reset(realm)} /> )} ), }, { title: t("oid4vciAttributes"), isHidden: !openId4vciEnabled, panel: ( ({ key: p, value: p, }))} data-testid="signed-metadata-signing-algorithm" /> {requestEncryptionRequired === "true" && ( )} {t("timeClaimCorrelationMitigation")} {strategy === "randomize" && ( )} {strategy === "round" && ( )} reset(realm)} /> ), }, ]; return ( ); };