/* eslint-disable */ // @ts-nocheck import type AuthenticationFlowRepresentation from "@keycloak/keycloak-admin-client/lib/defs/authenticationFlowRepresentation"; import type IdentityProviderRepresentation from "@keycloak/keycloak-admin-client/lib/defs/identityProviderRepresentation"; import { FormErrorText, HelpItem, KeycloakSelect, SelectControl, SelectVariant, useFetch, } from "../../../shared/keycloak-ui-shared"; import { FormGroup, SelectOption, Switch, TextInput, ValidatedOptions, } from "../../../shared/@patternfly/react-core"; import { useState } from "react"; import { Controller, useFormContext, useWatch } from "react-hook-form"; import { useTranslation } from "react-i18next"; import { useAdminClient } from "../../admin-client"; import useIsFeatureEnabled, { Feature } from "../../utils/useIsFeatureEnabled"; import type { FieldProps } from "../component/FormGroupField"; import { FormGroupField } from "../component/FormGroupField"; import { SwitchField } from "../component/SwitchField"; import { TextField } from "../component/TextField"; import { TimeSelector } from "../../components/time-selector/TimeSelector"; const LoginFlow = ({ field, label, defaultValue, labelForEmpty = "none", }: FieldProps & { defaultValue: string; labelForEmpty?: string }) => { const { adminClient } = useAdminClient(); const { t } = useTranslation(); const { control } = useFormContext(); const [flows, setFlows] = useState(); const [open, setOpen] = useState(false); useFetch( () => adminClient.authenticationManagement.getFlows(), (flows) => setFlows(flows.filter((flow) => flow.providerId === "basic-flow")), [], ); return ( } fieldId={label} > ( setOpen(!open)} onSelect={(value) => { field.onChange(value as string); setOpen(false); }} selections={field.value || t(labelForEmpty)} variant={SelectVariant.single} aria-label={t(label)} isOpen={open} > {[ ...(defaultValue === "" ? [ {t(labelForEmpty)} , ] : []), ...(flows?.map((option) => ( {option.alias} )) || []), ]} )} /> ); }; const SYNC_MODES = ["IMPORT", "LEGACY", "FORCE"]; const SHOW_IN_ACCOUNT_CONSOLE_VALUES = ["ALWAYS", "WHEN_LINKED", "NEVER"]; type AdvancedSettingsProps = { isOIDC: boolean; isSAML: boolean; isOAuth2: boolean; }; export const AdvancedSettings = ({ isOIDC, isSAML, isOAuth2, }: AdvancedSettingsProps) => { const { adminClient } = useAdminClient(); const { t } = useTranslation(); const { control, register, setValue, formState: { errors }, } = useFormContext(); const filteredByClaim = useWatch({ control, name: "config.filteredByClaim", defaultValue: "false", }); const claimFilterRequired = filteredByClaim === "true"; const isFeatureEnabled = useIsFeatureEnabled(); const isTransientUsersEnabled = isFeatureEnabled(Feature.TransientUsers); const isClientAuthFederatedEnabled = isFeatureEnabled( Feature.ClientAuthFederated, ); const jwtAuthorizationGrant = isFeatureEnabled(Feature.JWTAuthorizationGrant); const isIdentityBrokeringAPIV1Enabled = isFeatureEnabled( Feature.IdentityBrokeringAPIV1, ); const transientUsers = useWatch({ control, name: "config.doNotStoreUsers", defaultValue: "false", }); const syncModeAvailable = transientUsers === "false"; const jwtAuthorizationGrantEnabled = useWatch({ control, name: "config.jwtAuthorizationGrantEnabled", }); const supportsClientAssertions = useWatch({ control, name: "config.supportsClientAssertions", }); const [hasBrokerReadTokenRole, setHasBrokerReadTokenRole] = useState(false); useFetch( async () => { const brokerClient = (await adminClient.clients.find()).find( (client) => client.clientId === "broker", ); if (!brokerClient?.id) { return false; } const role = await adminClient.clients.findRole({ id: brokerClient.id, roleName: "read-token", }); return !!role; }, (hasRole) => { setHasBrokerReadTokenRole(hasRole); }, [], ); return ( <> {!isOIDC && !isSAML && !isOAuth2 && ( )} {isFeatureEnabled(Feature.IdentityBrokeringAPIV2) && ( )} {(isSAML || isOIDC || isOAuth2) && isIdentityBrokeringAPIV1Enabled && hasBrokerReadTokenRole && ( )} {!isOIDC && !isSAML && !isOAuth2 && ( <> )} {isOIDC && ( )} ({ key: showInAccountConsole, value: t( `showInAccountConsole.${showInAccountConsole.toLocaleLowerCase()}`, ), }))} controller={{ defaultValue: SHOW_IN_ACCOUNT_CONSOLE_VALUES[0], rules: { required: t("required") }, }} /> {((!isSAML && !isOAuth2) || isOIDC) && ( ( { field.onChange(value.toString()); }} /> )} /> )} {(!isSAML || isOIDC) && claimFilterRequired && ( <> } fieldId="kc-claim-filter-name" isRequired > {errors.config?.claimFilterName && ( )} } fieldId="kc-claim-filter-value" isRequired > {errors.config?.claimFilterValue && ( )} )} {isTransientUsersEnabled && ( ( { field.onChange(value.toString()); // if field is checked, set sync mode to import if (value) { setValue("config.syncMode", "IMPORT", { shouldDirty: true, }); } }} /> )} /> )} {syncModeAvailable && ( ({ key: syncMode, value: t(`syncModes.${syncMode.toLocaleLowerCase()}`), }))} controller={{ defaultValue: SYNC_MODES[0], rules: { required: t("required") }, }} /> )} {isClientAuthFederatedEnabled && isOIDC && ( )} {isClientAuthFederatedEnabled && isOIDC && supportsClientAssertions === "true" && ( )} {isOIDC && ((isClientAuthFederatedEnabled && supportsClientAssertions === "true") || (jwtAuthorizationGrant && jwtAuthorizationGrantEnabled === "true")) && ( )} {isOIDC && ((isClientAuthFederatedEnabled && supportsClientAssertions === "true") || (jwtAuthorizationGrant && jwtAuthorizationGrantEnabled === "true")) && ( ( )} /> )} ); };