2022-05-30 11:07:33 +00:00
|
|
|
import { useTranslation } from "react-i18next";
|
|
|
|
import { Controller, useFormContext } from "react-hook-form";
|
|
|
|
import { FormGroup, Switch, ValidatedOptions } from "@patternfly/react-core";
|
|
|
|
|
|
|
|
import type ClientRepresentation from "@keycloak/keycloak-admin-client/lib/defs/clientRepresentation";
|
|
|
|
import type { ClientSettingsProps } from "../ClientSettings";
|
|
|
|
import { FormAccess } from "../../components/form-access/FormAccess";
|
|
|
|
import { HelpItem } from "../../components/help-enabler/HelpItem";
|
|
|
|
import { KeycloakTextInput } from "../../components/keycloak-text-input/KeycloakTextInput";
|
|
|
|
import { useAccess } from "../../context/access/Access";
|
|
|
|
import { SaveReset } from "../advanced/SaveReset";
|
2022-08-09 08:32:16 +00:00
|
|
|
import { convertAttributeNameToForm } from "../../util";
|
2022-05-30 11:07:33 +00:00
|
|
|
|
|
|
|
export const LogoutPanel = ({
|
|
|
|
save,
|
|
|
|
reset,
|
|
|
|
client: { access },
|
|
|
|
}: ClientSettingsProps) => {
|
|
|
|
const { t } = useTranslation("clients");
|
|
|
|
const {
|
|
|
|
register,
|
|
|
|
control,
|
|
|
|
watch,
|
|
|
|
formState: { errors },
|
|
|
|
} = useFormContext<ClientRepresentation>();
|
|
|
|
|
|
|
|
const { hasAccess } = useAccess();
|
|
|
|
const isManager = hasAccess("manage-clients") || access?.configure;
|
|
|
|
|
|
|
|
const protocol = watch("protocol");
|
|
|
|
const frontchannelLogout = watch("frontchannelLogout");
|
|
|
|
|
|
|
|
return (
|
|
|
|
<FormAccess
|
|
|
|
isHorizontal
|
|
|
|
fineGrainedAccess={access?.configure}
|
|
|
|
role="manage-clients"
|
|
|
|
>
|
2022-06-24 11:31:02 +00:00
|
|
|
<FormGroup
|
|
|
|
label={t("frontchannelLogout")}
|
|
|
|
labelIcon={
|
|
|
|
<HelpItem
|
|
|
|
helpText="clients-help:frontchannelLogout"
|
|
|
|
fieldLabelId="clients:frontchannelLogout"
|
|
|
|
/>
|
|
|
|
}
|
|
|
|
fieldId="kc-frontchannelLogout"
|
|
|
|
hasNoPaddingTop
|
|
|
|
>
|
|
|
|
<Controller
|
|
|
|
name="frontchannelLogout"
|
|
|
|
defaultValue={true}
|
|
|
|
control={control}
|
|
|
|
render={({ onChange, value }) => (
|
|
|
|
<Switch
|
|
|
|
id="kc-frontchannelLogout-switch"
|
|
|
|
label={t("common:on")}
|
|
|
|
labelOff={t("common:off")}
|
2022-06-27 08:41:57 +00:00
|
|
|
isChecked={value}
|
|
|
|
onChange={onChange}
|
2022-08-30 13:07:51 +00:00
|
|
|
aria-label={t("frontchannelLogout")}
|
2022-06-24 11:31:02 +00:00
|
|
|
/>
|
|
|
|
)}
|
|
|
|
/>
|
|
|
|
</FormGroup>
|
2022-06-27 08:41:57 +00:00
|
|
|
{protocol === "openid-connect" && frontchannelLogout && (
|
|
|
|
<FormGroup
|
|
|
|
label={t("frontchannelLogoutUrl")}
|
|
|
|
fieldId="frontchannelLogoutUrl"
|
|
|
|
labelIcon={
|
|
|
|
<HelpItem
|
|
|
|
helpText="clients-help:frontchannelLogoutUrl"
|
|
|
|
fieldLabelId="clients:frontchannelLogoutUrl"
|
|
|
|
/>
|
|
|
|
}
|
|
|
|
helperTextInvalid={
|
|
|
|
errors.attributes?.frontchannel?.logout?.url?.message
|
|
|
|
}
|
|
|
|
validated={
|
|
|
|
errors.attributes?.frontchannel?.logout?.url?.message
|
|
|
|
? ValidatedOptions.error
|
|
|
|
: ValidatedOptions.default
|
|
|
|
}
|
|
|
|
>
|
|
|
|
<KeycloakTextInput
|
|
|
|
type="text"
|
|
|
|
id="frontchannelLogoutUrl"
|
2022-08-09 08:32:16 +00:00
|
|
|
name={convertAttributeNameToForm(
|
|
|
|
"attributes.frontchannel.logout.url"
|
|
|
|
)}
|
2022-06-27 08:41:57 +00:00
|
|
|
ref={register({
|
|
|
|
validate: (uri) =>
|
|
|
|
((uri.startsWith("https://") || uri.startsWith("http://")) &&
|
|
|
|
!uri.includes("*")) ||
|
|
|
|
uri === "" ||
|
|
|
|
t("frontchannelUrlInvalid").toString(),
|
|
|
|
})}
|
2022-06-24 11:31:02 +00:00
|
|
|
validated={
|
|
|
|
errors.attributes?.frontchannel?.logout?.url?.message
|
|
|
|
? ValidatedOptions.error
|
|
|
|
: ValidatedOptions.default
|
|
|
|
}
|
2022-06-27 08:41:57 +00:00
|
|
|
/>
|
|
|
|
</FormGroup>
|
|
|
|
)}
|
2022-07-13 19:13:47 +00:00
|
|
|
{protocol === "openid-connect" && (
|
|
|
|
<>
|
|
|
|
<FormGroup
|
|
|
|
label={t("backchannelLogoutUrl")}
|
|
|
|
fieldId="backchannelLogoutUrl"
|
|
|
|
labelIcon={
|
|
|
|
<HelpItem
|
|
|
|
helpText="clients-help:backchannelLogoutUrl"
|
|
|
|
fieldLabelId="clients:backchannelLogoutUrl"
|
|
|
|
/>
|
|
|
|
}
|
|
|
|
helperTextInvalid={
|
|
|
|
errors.attributes?.backchannel?.logout?.url?.message
|
|
|
|
}
|
|
|
|
validated={
|
|
|
|
errors.attributes?.backchannel?.logout?.url?.message
|
|
|
|
? ValidatedOptions.error
|
|
|
|
: ValidatedOptions.default
|
|
|
|
}
|
|
|
|
>
|
|
|
|
<KeycloakTextInput
|
|
|
|
type="text"
|
|
|
|
id="backchannelLogoutUrl"
|
2022-08-09 08:32:16 +00:00
|
|
|
name={convertAttributeNameToForm(
|
|
|
|
"attributes.backchannel.logout.url"
|
|
|
|
)}
|
2022-07-13 19:13:47 +00:00
|
|
|
ref={register({
|
|
|
|
validate: (uri) =>
|
|
|
|
((uri.startsWith("https://") || uri.startsWith("http://")) &&
|
|
|
|
!uri.includes("*")) ||
|
|
|
|
uri === "" ||
|
|
|
|
t("backchannelUrlInvalid").toString(),
|
|
|
|
})}
|
|
|
|
validated={
|
|
|
|
errors.attributes?.backchannel?.logout?.url?.message
|
|
|
|
? ValidatedOptions.error
|
|
|
|
: ValidatedOptions.default
|
|
|
|
}
|
2022-05-30 11:07:33 +00:00
|
|
|
/>
|
2022-07-13 19:13:47 +00:00
|
|
|
</FormGroup>
|
|
|
|
<FormGroup
|
|
|
|
label={t("backchannelLogoutSessionRequired")}
|
|
|
|
labelIcon={
|
|
|
|
<HelpItem
|
|
|
|
helpText="clients-help:backchannelLogoutSessionRequired"
|
|
|
|
fieldLabelId="clients:backchannelLogoutSessionRequired"
|
|
|
|
/>
|
|
|
|
}
|
|
|
|
fieldId="backchannelLogoutSessionRequired"
|
|
|
|
hasNoPaddingTop
|
|
|
|
>
|
|
|
|
<Controller
|
2022-08-09 08:32:16 +00:00
|
|
|
name={convertAttributeNameToForm(
|
|
|
|
"attributes.backchannel.logout.session.required"
|
|
|
|
)}
|
2022-07-13 19:13:47 +00:00
|
|
|
defaultValue="true"
|
|
|
|
control={control}
|
|
|
|
render={({ onChange, value }) => (
|
|
|
|
<Switch
|
|
|
|
id="backchannelLogoutSessionRequired"
|
|
|
|
label={t("common:on")}
|
|
|
|
labelOff={t("common:off")}
|
|
|
|
isChecked={value === "true"}
|
|
|
|
onChange={(value) => onChange(value.toString())}
|
2022-08-30 13:07:51 +00:00
|
|
|
aria-label={t("backchannelLogoutSessionRequired")}
|
2022-07-13 19:13:47 +00:00
|
|
|
/>
|
|
|
|
)}
|
2022-05-30 11:07:33 +00:00
|
|
|
/>
|
2022-07-13 19:13:47 +00:00
|
|
|
</FormGroup>
|
|
|
|
<FormGroup
|
|
|
|
label={t("backchannelLogoutRevokeOfflineSessions")}
|
|
|
|
labelIcon={
|
|
|
|
<HelpItem
|
|
|
|
helpText="clients-help:backchannelLogoutRevokeOfflineSessions"
|
|
|
|
fieldLabelId="clients:backchannelLogoutRevokeOfflineSessions"
|
|
|
|
/>
|
|
|
|
}
|
|
|
|
fieldId="backchannelLogoutRevokeOfflineSessions"
|
|
|
|
hasNoPaddingTop
|
|
|
|
>
|
|
|
|
<Controller
|
2022-08-09 08:32:16 +00:00
|
|
|
name={convertAttributeNameToForm(
|
|
|
|
"attributes.backchannel.logout.revoke.offline.tokens"
|
|
|
|
)}
|
2022-07-13 19:13:47 +00:00
|
|
|
defaultValue="false"
|
|
|
|
control={control}
|
|
|
|
render={({ onChange, value }) => (
|
|
|
|
<Switch
|
|
|
|
id="backchannelLogoutRevokeOfflineSessions"
|
|
|
|
label={t("common:on")}
|
|
|
|
labelOff={t("common:off")}
|
|
|
|
isChecked={value === "true"}
|
|
|
|
onChange={(value) => onChange(value.toString())}
|
2022-08-30 13:07:51 +00:00
|
|
|
aria-label={t("backchannelLogoutRevokeOfflineSessions")}
|
2022-07-13 19:13:47 +00:00
|
|
|
/>
|
|
|
|
)}
|
|
|
|
/>
|
|
|
|
</FormGroup>
|
|
|
|
</>
|
|
|
|
)}
|
2022-05-30 11:07:33 +00:00
|
|
|
<SaveReset
|
|
|
|
className="keycloak__form_actions"
|
|
|
|
name="settings"
|
|
|
|
save={save}
|
|
|
|
reset={reset}
|
|
|
|
isActive={isManager}
|
|
|
|
/>
|
|
|
|
</FormAccess>
|
|
|
|
);
|
|
|
|
};
|