keycloak-scim/js/apps/admin-ui/src/clients/add/SamlConfig.tsx

141 lines
3.8 KiB
TypeScript
Raw Normal View History

2021-10-05 10:32:20 +00:00
import {
FormGroup,
Select,
SelectOption,
SelectVariant,
Switch,
} from "@patternfly/react-core";
import { useState } from "react";
import { Controller, Path, PathValue, useFormContext } from "react-hook-form";
import { useTranslation } from "react-i18next";
2021-10-05 10:32:20 +00:00
import { FormAccess } from "../../components/form/FormAccess";
2023-03-07 09:29:40 +00:00
import { HelpItem } from "ui-shared";
import { convertAttributeNameToForm } from "../../util";
import { FormFields } from "../ClientDetails";
2021-10-05 10:32:20 +00:00
type ToggleProps = {
name: PathValue<FormFields, Path<FormFields>>;
label: string;
};
export const Toggle = ({ name, label }: ToggleProps) => {
const { t } = useTranslation();
const { control } = useFormContext<FormFields>();
2021-10-05 10:32:20 +00:00
return (
<FormGroup
hasNoPaddingTop
label={t(label)}
fieldId={label}
labelIcon={
<HelpItem
helpText={t(`clients-help:${label}`)}
2021-12-14 14:56:36 +00:00
fieldLabelId={`clients:${label}`}
2021-10-05 10:32:20 +00:00
/>
}
>
<Controller
name={name}
defaultValue="false"
control={control}
render={({ field }) => (
2021-10-05 10:32:20 +00:00
<Switch
id={name!}
data-testid={label}
label={t("common:on")}
labelOff={t("common:off")}
isChecked={field.value === "true"}
onChange={(value) => field.onChange(value.toString())}
aria-label={t(label)}
2021-10-05 10:32:20 +00:00
/>
)}
/>
</FormGroup>
);
};
export const SamlConfig = () => {
const { t } = useTranslation();
const { control } = useFormContext<FormFields>();
2021-10-05 10:32:20 +00:00
const [nameFormatOpen, setNameFormatOpen] = useState(false);
return (
<FormAccess
isHorizontal
role="manage-clients"
className="keycloak__capability-config__form"
>
<FormGroup
label={t("nameIdFormat")}
fieldId="nameIdFormat"
labelIcon={
<HelpItem
helpText={t("nameIdFormatHelp")}
2021-12-14 14:56:36 +00:00
fieldLabelId="clients:nameIdFormat"
2021-10-05 10:32:20 +00:00
/>
}
>
<Controller
name="attributes.saml_name_id_format"
defaultValue="username"
control={control}
render={({ field }) => (
2021-10-05 10:32:20 +00:00
<Select
toggleId="samlNameIdFormat"
onToggle={setNameFormatOpen}
2021-10-05 10:32:20 +00:00
onSelect={(_, value) => {
field.onChange(value.toString());
2021-10-05 10:32:20 +00:00
setNameFormatOpen(false);
}}
selections={field.value}
2021-10-05 10:32:20 +00:00
variant={SelectVariant.single}
aria-label={t("nameIdFormat")}
isOpen={nameFormatOpen}
>
{["username", "email", "transient", "persistent"].map((name) => (
<SelectOption
selected={name === field.value}
2021-10-05 10:32:20 +00:00
key={name}
value={name}
/>
))}
</Select>
)}
/>
</FormGroup>
<Toggle
name="attributes.saml_force_name_id_format"
2021-10-05 10:32:20 +00:00
label="forceNameIdFormat"
/>
<Toggle
name={convertAttributeNameToForm("attributes.saml.force.post.binding")}
2021-10-05 10:32:20 +00:00
label="forcePostBinding"
/>
<Toggle
name={convertAttributeNameToForm("attributes.saml.artifact.binding")}
2021-10-05 10:32:20 +00:00
label="forceArtifactBinding"
/>
2022-03-02 21:38:52 +00:00
<Toggle
name={convertAttributeNameToForm("attributes.saml.authnstatement")}
2022-03-02 21:38:52 +00:00
label="includeAuthnStatement"
/>
2021-10-05 10:32:20 +00:00
<Toggle
name={convertAttributeNameToForm(
"attributes.saml.onetimeuse.condition",
)}
2021-10-05 10:32:20 +00:00
label="includeOneTimeUseCondition"
/>
<Toggle
name={convertAttributeNameToForm(
"attributes.saml.server.signature.keyinfo.ext",
)}
2021-10-05 10:32:20 +00:00
label="optimizeLookup"
/>
<Toggle
name={convertAttributeNameToForm("attributes.saml.allow.ecp.flow")}
label="allowEcpFlow"
/>
2021-10-05 10:32:20 +00:00
</FormAccess>
);
};