2022-05-30 11:07:33 +00:00
|
|
|
import { FormGroup, Switch, ValidatedOptions } from "@patternfly/react-core";
|
2023-01-26 09:31:07 +00:00
|
|
|
import { Controller, useFormContext } from "react-hook-form";
|
2022-12-02 14:54:30 +00:00
|
|
|
import { useTranslation } from "react-i18next";
|
2022-05-30 11:07:33 +00:00
|
|
|
|
|
|
|
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";
|
2022-12-02 14:54:30 +00:00
|
|
|
import { beerify, convertAttributeNameToForm } from "../../util";
|
2022-05-30 11:07:33 +00:00
|
|
|
import { SaveReset } from "../advanced/SaveReset";
|
2022-12-02 14:54:30 +00:00
|
|
|
import type { ClientSettingsProps } from "../ClientSettings";
|
|
|
|
import { FormFields } from "../ClientDetails";
|
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 },
|
2022-12-02 14:54:30 +00:00
|
|
|
} = useFormContext<FormFields>();
|
2022-05-30 11:07:33 +00:00
|
|
|
|
|
|
|
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}
|
2022-12-02 14:54:30 +00:00
|
|
|
render={({ field }) => (
|
2022-06-24 11:31:02 +00:00
|
|
|
<Switch
|
|
|
|
id="kc-frontchannelLogout-switch"
|
|
|
|
label={t("common:on")}
|
|
|
|
labelOff={t("common:off")}
|
2022-12-02 14:54:30 +00:00
|
|
|
isChecked={field.value}
|
|
|
|
onChange={field.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={
|
2022-12-02 14:54:30 +00:00
|
|
|
errors.attributes?.[beerify("frontchannel.logout.url")]?.message
|
2022-06-27 08:41:57 +00:00
|
|
|
}
|
|
|
|
validated={
|
2022-12-02 14:54:30 +00:00
|
|
|
errors.attributes?.[beerify("frontchannel.logout.url")]?.message
|
2022-06-27 08:41:57 +00:00
|
|
|
? ValidatedOptions.error
|
|
|
|
: ValidatedOptions.default
|
|
|
|
}
|
|
|
|
>
|
|
|
|
<KeycloakTextInput
|
|
|
|
id="frontchannelLogoutUrl"
|
2022-12-07 09:04:37 +00:00
|
|
|
type="url"
|
2022-12-02 14:54:30 +00:00
|
|
|
{...register(
|
|
|
|
convertAttributeNameToForm<FormFields>(
|
|
|
|
"attributes.frontchannel.logout.url"
|
|
|
|
),
|
|
|
|
{
|
|
|
|
validate: (uri) =>
|
|
|
|
((uri.startsWith("https://") || uri.startsWith("http://")) &&
|
|
|
|
!uri.includes("*")) ||
|
|
|
|
uri === "" ||
|
|
|
|
t("frontchannelUrlInvalid").toString(),
|
|
|
|
}
|
2022-08-09 08:32:16 +00:00
|
|
|
)}
|
2022-06-24 11:31:02 +00:00
|
|
|
validated={
|
2022-12-02 14:54:30 +00:00
|
|
|
errors.attributes?.[beerify("frontchannel.logout.url")]?.message
|
2022-06-24 11:31:02 +00:00
|
|
|
? 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={
|
2022-12-02 14:54:30 +00:00
|
|
|
errors.attributes?.[beerify("backchannel.logout.url")]?.message
|
2022-07-13 19:13:47 +00:00
|
|
|
}
|
|
|
|
validated={
|
2022-12-02 14:54:30 +00:00
|
|
|
errors.attributes?.[beerify("backchannel.logout.url")]?.message
|
2022-07-13 19:13:47 +00:00
|
|
|
? ValidatedOptions.error
|
|
|
|
: ValidatedOptions.default
|
|
|
|
}
|
|
|
|
>
|
|
|
|
<KeycloakTextInput
|
|
|
|
id="backchannelLogoutUrl"
|
2022-12-07 09:04:37 +00:00
|
|
|
type="url"
|
2022-12-02 14:54:30 +00:00
|
|
|
{...register(
|
|
|
|
convertAttributeNameToForm<FormFields>(
|
|
|
|
"attributes.backchannel.logout.url"
|
|
|
|
),
|
|
|
|
{
|
|
|
|
validate: (uri) =>
|
|
|
|
((uri.startsWith("https://") ||
|
|
|
|
uri.startsWith("http://")) &&
|
|
|
|
!uri.includes("*")) ||
|
|
|
|
uri === "" ||
|
|
|
|
t("backchannelUrlInvalid").toString(),
|
|
|
|
}
|
2022-08-09 08:32:16 +00:00
|
|
|
)}
|
2022-07-13 19:13:47 +00:00
|
|
|
validated={
|
2022-12-02 14:54:30 +00:00
|
|
|
errors.attributes?.[beerify("backchannel.logout.url")]?.message
|
2022-07-13 19:13:47 +00:00
|
|
|
? 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-12-02 14:54:30 +00:00
|
|
|
name={convertAttributeNameToForm<FormFields>(
|
2022-08-09 08:32:16 +00:00
|
|
|
"attributes.backchannel.logout.session.required"
|
|
|
|
)}
|
2022-07-13 19:13:47 +00:00
|
|
|
defaultValue="true"
|
|
|
|
control={control}
|
2022-12-02 14:54:30 +00:00
|
|
|
render={({ field }) => (
|
2022-07-13 19:13:47 +00:00
|
|
|
<Switch
|
|
|
|
id="backchannelLogoutSessionRequired"
|
|
|
|
label={t("common:on")}
|
|
|
|
labelOff={t("common:off")}
|
2022-12-02 14:54:30 +00:00
|
|
|
isChecked={field.value === "true"}
|
|
|
|
onChange={(value) => field.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-12-02 14:54:30 +00:00
|
|
|
name={convertAttributeNameToForm<FormFields>(
|
2022-08-09 08:32:16 +00:00
|
|
|
"attributes.backchannel.logout.revoke.offline.tokens"
|
|
|
|
)}
|
2022-07-13 19:13:47 +00:00
|
|
|
defaultValue="false"
|
|
|
|
control={control}
|
2022-12-02 14:54:30 +00:00
|
|
|
render={({ field }) => (
|
2022-07-13 19:13:47 +00:00
|
|
|
<Switch
|
|
|
|
id="backchannelLogoutRevokeOfflineSessions"
|
|
|
|
label={t("common:on")}
|
|
|
|
labelOff={t("common:off")}
|
2022-12-02 14:54:30 +00:00
|
|
|
isChecked={field.value === "true"}
|
|
|
|
onChange={(value) => field.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>
|
|
|
|
);
|
|
|
|
};
|