import React, { useState } from "react"; import { useTranslation } from "react-i18next"; import { Controller, useFormContext, 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 } from "../components/time-selector/TimeSelector"; import { useServerInfo } from "../context/server-info/ServerInfoProvider"; import { forHumans, interpolateTimespan } from "../util"; import "./RealmSettingsSection.css"; 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 [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 = useFormContext(); const { control } = form; const offlineSessionMaxEnabled = useWatch({ control, name: "offlineSessionMaxLifespanEnabled", defaultValue: realm.offlineSessionMaxLifespanEnabled, }); return ( } > ( )} /> } > ( )} /> } fieldId="refreshTokenMaxReuse" > ( onChange(value + 1)} onMinus={() => onChange(value - 1)} onChange={(event) => onChange(Number((event.target as HTMLInputElement).value)) } /> )} /> } > ( realm.ssoSessionIdleTimeout! ? "warning" : "default" } className="kc-access-token-lifespan" data-testid="access-token-lifespan-input" aria-label="access-token-lifespan" value={value} onChange={onChange} units={["minutes", "hours", "days"]} /> )} /> } > ( )} /> } > ( )} /> {offlineSessionMaxEnabled && ( } > ( )} /> )} } > ( )} /> } > ( )} /> {t("overrideActionTokens")} ( onChange(value.toString())} units={["minutes", "hours", "days"]} /> )} /> ( )} /> ( )} /> ( )} /> ); };