import { useEffect, useState } from "react"; import { useTranslation } from "react-i18next"; import { Controller, useForm, useWatch } from "react-hook-form"; import { ActionGroup, Button, FormGroup, NumberInput, PageSection, Select, SelectOption, SelectVariant, Switch, Text, TextVariants, } from "@patternfly/react-core"; import type RealmRepresentation from "@keycloak/keycloak-admin-client/lib/defs/realmRepresentation"; import { FormAccess } from "../components/form-access/FormAccess"; import { HelpItem } from "../components/help-enabler/HelpItem"; import { FormPanel } from "../components/scroll-form/FormPanel"; import { TimeSelector, toHumanFormat, } from "../components/time-selector/TimeSelector"; import { useServerInfo } from "../context/server-info/ServerInfoProvider"; import "./realm-settings-section.css"; import { useWhoAmI } from "../context/whoami/WhoAmI"; import { convertToFormValues } from "../util"; type RealmSettingsSessionsTabProps = { realm: RealmRepresentation; save: (realm: RealmRepresentation) => void; reset?: () => void; }; export const RealmSettingsTokensTab = ({ realm, reset, save, }: RealmSettingsSessionsTabProps) => { const { t } = useTranslation("realm-settings"); const serverInfo = useServerInfo(); const { whoAmI } = useWhoAmI(); const [defaultSigAlgDrpdwnIsOpen, setDefaultSigAlgDrpdwnOpen] = useState(false); const allComponentTypes = serverInfo.componentTypes?.["org.keycloak.keys.KeyProvider"] ?? []; const esOptions = ["ES256", "ES384", "ES512"]; const hmacAlgorithmOptions = allComponentTypes[2].properties[4].options; const javaKeystoreAlgOptions = allComponentTypes[3].properties[3].options; const defaultSigAlgOptions = esOptions.concat( hmacAlgorithmOptions!, javaKeystoreAlgOptions! ); const form = useForm({ shouldUnregister: false }); 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 ( } > ( )} /> } > ( )} /> {revokeRefreshToken && ( } fieldId="refreshTokenMaxReuse" > ( onChange(value + 1)} onMinus={() => onChange(value - 1)} onChange={(event) => onChange(Number((event.target as HTMLInputElement).value)) } /> )} /> )} } > ( ssoSessionIdleTimeout! ? "warning" : "default" } className="kc-access-token-lifespan" data-testid="access-token-lifespan-input" aria-label="access-token-lifespan" value={value} onChange={onChange} units={["minute", "hour", "day"]} /> )} /> } > ( )} /> } > ( )} /> {offlineSessionMaxEnabled && ( } > ( )} /> )} } > ( )} /> } > ( )} /> {t("overrideActionTokens")} ( onChange(value.toString())} units={["minute", "hour", "day"]} /> )} /> ( )} /> ( )} /> ( )} /> ); };