import type ClientRepresentation from "@keycloak/keycloak-admin-client/lib/defs/clientRepresentation"; import React, { useMemo, useState } from "react"; import { useTranslation } from "react-i18next"; import { FormGroup, Form, Switch, Select, SelectVariant, SelectOption, ValidatedOptions, } from "@patternfly/react-core"; import { Controller, useFormContext } from "react-hook-form"; import { ScrollForm } from "../components/scroll-form/ScrollForm"; import { ClientDescription } from "./ClientDescription"; import { CapabilityConfig } from "./add/CapabilityConfig"; import { MultiLineInput } from "../components/multi-line-input/MultiLineInput"; import { FormAccess } from "../components/form-access/FormAccess"; import { HelpItem } from "../components/help-enabler/HelpItem"; import { KeycloakTextInput } from "../components/keycloak-text-input/KeycloakTextInput"; import { KeycloakTextArea } from "../components/keycloak-text-area/KeycloakTextArea"; import { useServerInfo } from "../context/server-info/ServerInfoProvider"; import { SaveReset } from "./advanced/SaveReset"; import { SamlConfig } from "./add/SamlConfig"; import { SamlSignature } from "./add/SamlSignature"; import environment from "../environment"; import { useRealm } from "../context/realm-context/RealmContext"; import { useAccess } from "../context/access/Access"; type ClientSettingsProps = { client: ClientRepresentation; save: () => void; reset: () => void; }; export const ClientSettings = ({ client, save, reset, }: ClientSettingsProps) => { const { register, control, watch, formState: { errors }, } = useFormContext(); const { t } = useTranslation("clients"); const { realm } = useRealm(); const { hasAccess } = useAccess(); const isManager = hasAccess("manage-clients") || client.access?.configure; const [loginThemeOpen, setLoginThemeOpen] = useState(false); const loginThemes = useServerInfo().themes!["login"]; const consentRequired = watch("consentRequired"); const displayOnConsentScreen: string = watch( "attributes.display.on.consent.screen" ); const protocol = watch("protocol"); const frontchannelLogout = watch("frontchannelLogout"); const idpInitiatedSsoUrlName: string = watch( "attributes.saml_idp_initiated_sso_url_name" ); const sections = useMemo(() => { let result = ["generalSettings", "accessSettings"]; if (protocol === "saml") { return [ ...result, "samlCapabilityConfig", "signatureAndEncryption", "loginSettings", ]; } else if (!client.bearerOnly) { result = [...result, "capabilityConfig"]; } else { return result; } return [...result, "loginSettings", "logoutSettings"]; }, [protocol, client]); return ( t(section))} >
{protocol === "saml" ? ( ) : ( !client.bearerOnly && )} {protocol === "saml" && } {!client.bearerOnly && ( <> } > } > } > {protocol === "saml" && ( <> } helperText={ idpInitiatedSsoUrlName !== "" && t("idpInitiatedSsoUrlNameHelp", { url: `${environment.authServerUrl}/realms/${realm}/protocol/saml/clients/${idpInitiatedSsoUrlName}`, }) } > } > } > )} {protocol !== "saml" && ( } > )} )} {protocol !== "saml" && ( } > )} {client.bearerOnly && ( )} } fieldId="loginTheme" > ( )} /> } fieldId="kc-consent" hasNoPaddingTop > ( )} /> } fieldId="kc-display-on-client" hasNoPaddingTop > ( onChange("" + value)} isDisabled={!consentRequired} /> )} /> } fieldId="kc-consent-screen-text" > {protocol === "saml" && ( )} {protocol === "openid-connect" && ( <> } fieldId="frontchannelLogout" hasNoPaddingTop > ( onChange(value.toString())} /> )} /> {frontchannelLogout?.toString() === "true" && ( } helperTextInvalid={ errors.attributes?.frontchannel?.logout?.url?.message } validated={ errors.attributes?.frontchannel?.logout?.url?.message ? ValidatedOptions.error : ValidatedOptions.default } > ((uri.startsWith("https://") || uri.startsWith("http://")) && !uri.includes("*")) || uri === "" || t("frontchannelUrlInvalid").toString(), })} validated={ errors.attributes?.frontchannel?.logout?.url?.message ? ValidatedOptions.error : ValidatedOptions.default } /> )} )} } helperTextInvalid={ errors.attributes?.backchannel?.logout?.url?.message } validated={ errors.attributes?.backchannel?.logout?.url?.message ? ValidatedOptions.error : ValidatedOptions.default } > ((uri.startsWith("https://") || uri.startsWith("http://")) && !uri.includes("*")) || uri === "" || t("backchannelUrlInvalid").toString(), })} validated={ errors.attributes?.backchannel?.logout?.url?.message ? ValidatedOptions.error : ValidatedOptions.default } /> } fieldId="backchannelLogoutSessionRequired" hasNoPaddingTop > ( onChange(value.toString())} /> )} /> } fieldId="backchannelLogoutRevokeOfflineSessions" hasNoPaddingTop > ( onChange(value.toString())} /> )} />
); };