2021-04-29 06:28:59 +00:00
|
|
|
import React, { useState } from "react";
|
2020-11-02 20:15:09 +00:00
|
|
|
import {
|
2021-03-17 07:10:30 +00:00
|
|
|
Alert,
|
2020-11-02 20:15:09 +00:00
|
|
|
AlertVariant,
|
|
|
|
ButtonVariant,
|
2021-03-19 07:49:33 +00:00
|
|
|
Divider,
|
2020-11-02 20:15:09 +00:00
|
|
|
DropdownItem,
|
|
|
|
PageSection,
|
2020-11-30 19:33:31 +00:00
|
|
|
Spinner,
|
2020-11-02 20:15:09 +00:00
|
|
|
Tab,
|
2021-03-01 09:20:36 +00:00
|
|
|
Tabs,
|
2020-11-02 20:15:09 +00:00
|
|
|
TabTitleText,
|
|
|
|
} from "@patternfly/react-core";
|
2021-04-12 15:42:36 +00:00
|
|
|
import { useHistory, useParams } from "react-router-dom";
|
2020-11-02 20:15:09 +00:00
|
|
|
import { useTranslation } from "react-i18next";
|
2021-04-29 06:28:59 +00:00
|
|
|
import { Controller, FormProvider, useForm, useWatch } from "react-hook-form";
|
2021-05-04 17:58:18 +00:00
|
|
|
import type ClientRepresentation from "keycloak-admin/lib/defs/clientRepresentation";
|
2021-02-28 20:02:31 +00:00
|
|
|
import _ from "lodash";
|
2020-11-02 20:15:09 +00:00
|
|
|
|
|
|
|
import { ClientSettings } from "./ClientSettings";
|
|
|
|
import { useAlerts } from "../components/alert/Alerts";
|
2021-03-17 07:10:30 +00:00
|
|
|
import {
|
|
|
|
ConfirmDialogModal,
|
|
|
|
useConfirmDialog,
|
|
|
|
} from "../components/confirm-dialog/ConfirmDialog";
|
2021-02-28 20:02:31 +00:00
|
|
|
import { DownloadDialog } from "../components/download-dialog/DownloadDialog";
|
2020-11-02 20:15:09 +00:00
|
|
|
import { ViewHeader } from "../components/view-header/ViewHeader";
|
2021-04-29 06:28:59 +00:00
|
|
|
import { useAdminClient, useFetch } from "../context/auth/AdminClient";
|
2020-11-02 20:15:09 +00:00
|
|
|
import { Credentials } from "./credentials/Credentials";
|
|
|
|
import {
|
|
|
|
convertFormValuesToObject,
|
|
|
|
convertToFormValues,
|
|
|
|
exportClient,
|
|
|
|
} from "../util";
|
|
|
|
import {
|
|
|
|
convertToMultiline,
|
2021-02-28 20:02:31 +00:00
|
|
|
MultiLine,
|
2020-11-02 20:15:09 +00:00
|
|
|
toValue,
|
|
|
|
} from "../components/multi-line-input/MultiLineInput";
|
2020-11-24 20:11:13 +00:00
|
|
|
import { ClientScopes } from "./scopes/ClientScopes";
|
|
|
|
import { EvaluateScopes } from "./scopes/EvaluateScopes";
|
2021-01-29 13:59:03 +00:00
|
|
|
import { RolesList } from "../realm-roles/RolesList";
|
2020-12-07 18:37:36 +00:00
|
|
|
import { ServiceAccount } from "./service-account/ServiceAccount";
|
2021-01-13 20:47:40 +00:00
|
|
|
import { KeycloakTabs } from "../components/keycloak-tabs/KeycloakTabs";
|
2021-02-28 20:02:31 +00:00
|
|
|
import { AdvancedTab } from "./AdvancedTab";
|
2021-04-12 15:42:36 +00:00
|
|
|
import { useRealm } from "../context/realm-context/RealmContext";
|
2021-05-04 08:11:58 +00:00
|
|
|
import { Keys } from "./keys/Keys";
|
2020-11-02 20:15:09 +00:00
|
|
|
|
2020-11-30 19:33:31 +00:00
|
|
|
type ClientDetailHeaderProps = {
|
2021-02-08 20:50:03 +00:00
|
|
|
onChange: (value: boolean) => void;
|
|
|
|
value: boolean;
|
2020-11-30 19:33:31 +00:00
|
|
|
save: () => void;
|
|
|
|
client: ClientRepresentation;
|
|
|
|
toggleDownloadDialog: () => void;
|
|
|
|
toggleDeleteDialog: () => void;
|
|
|
|
};
|
|
|
|
|
|
|
|
const ClientDetailHeader = ({
|
|
|
|
onChange,
|
|
|
|
value,
|
|
|
|
save,
|
|
|
|
client,
|
|
|
|
toggleDownloadDialog,
|
|
|
|
toggleDeleteDialog,
|
|
|
|
}: ClientDetailHeaderProps) => {
|
|
|
|
const { t } = useTranslation("clients");
|
|
|
|
const [toggleDisableDialog, DisableConfirm] = useConfirmDialog({
|
|
|
|
titleKey: "clients:disableConfirmTitle",
|
|
|
|
messageKey: "clients:disableConfirm",
|
|
|
|
continueButtonLabel: "common:disable",
|
|
|
|
onConfirm: () => {
|
|
|
|
onChange(!value);
|
|
|
|
save();
|
|
|
|
},
|
|
|
|
});
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<DisableConfirm />
|
|
|
|
<ViewHeader
|
|
|
|
titleKey={client ? client.clientId! : ""}
|
|
|
|
subKey="clients:clientsExplain"
|
2021-03-19 07:49:33 +00:00
|
|
|
badge={client.protocol}
|
|
|
|
divider={false}
|
2020-11-30 19:33:31 +00:00
|
|
|
dropdownItems={[
|
|
|
|
<DropdownItem key="download" onClick={() => toggleDownloadDialog()}>
|
|
|
|
{t("downloadAdapterConfig")}
|
|
|
|
</DropdownItem>,
|
|
|
|
<DropdownItem key="export" onClick={() => exportClient(client)}>
|
|
|
|
{t("common:export")}
|
|
|
|
</DropdownItem>,
|
2021-03-19 07:49:33 +00:00
|
|
|
<Divider key="divider" />,
|
2020-11-30 19:33:31 +00:00
|
|
|
<DropdownItem key="delete" onClick={() => toggleDeleteDialog()}>
|
|
|
|
{t("common:delete")}
|
|
|
|
</DropdownItem>,
|
|
|
|
]}
|
|
|
|
isEnabled={value}
|
|
|
|
onToggle={(value) => {
|
|
|
|
if (!value) {
|
|
|
|
toggleDisableDialog();
|
|
|
|
} else {
|
|
|
|
onChange(value);
|
|
|
|
save();
|
|
|
|
}
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2021-02-28 20:02:31 +00:00
|
|
|
export type ClientForm = Omit<
|
|
|
|
ClientRepresentation,
|
|
|
|
"redirectUris" | "webOrigins"
|
|
|
|
> & {
|
|
|
|
redirectUris: MultiLine[];
|
|
|
|
webOrigins: MultiLine[];
|
|
|
|
};
|
|
|
|
|
2021-03-17 13:40:19 +00:00
|
|
|
export type SaveOptions = {
|
|
|
|
confirmed?: boolean;
|
|
|
|
messageKey?: string;
|
|
|
|
};
|
|
|
|
|
2020-11-02 20:15:09 +00:00
|
|
|
export const ClientDetails = () => {
|
|
|
|
const { t } = useTranslation("clients");
|
2020-11-12 12:55:52 +00:00
|
|
|
const adminClient = useAdminClient();
|
2021-04-12 15:42:36 +00:00
|
|
|
const { addAlert } = useAlerts();
|
|
|
|
const { realm } = useRealm();
|
|
|
|
|
|
|
|
const history = useHistory();
|
2021-02-17 21:12:25 +00:00
|
|
|
|
2021-02-28 20:02:31 +00:00
|
|
|
const [downloadDialogOpen, setDownloadDialogOpen] = useState(false);
|
|
|
|
const toggleDownloadDialog = () => setDownloadDialogOpen(!downloadDialogOpen);
|
2021-03-17 07:10:30 +00:00
|
|
|
const [changeAuthenticatorOpen, setChangeAuthenticatorOpen] = useState(false);
|
|
|
|
const toggleChangeAuthenticator = () =>
|
|
|
|
setChangeAuthenticatorOpen(!changeAuthenticatorOpen);
|
2021-03-01 09:20:36 +00:00
|
|
|
const [activeTab2, setActiveTab2] = useState(30);
|
2020-11-02 20:15:09 +00:00
|
|
|
|
2021-02-28 20:02:31 +00:00
|
|
|
const form = useForm<ClientForm>();
|
2021-03-01 09:20:36 +00:00
|
|
|
const { clientId } = useParams<{ clientId: string }>();
|
2020-11-02 20:15:09 +00:00
|
|
|
|
2021-04-29 06:28:59 +00:00
|
|
|
const clientAuthenticatorType = useWatch({
|
|
|
|
control: form.control,
|
|
|
|
name: "clientAuthenticatorType",
|
|
|
|
defaultValue: "client-secret",
|
|
|
|
});
|
|
|
|
|
2020-11-24 20:11:13 +00:00
|
|
|
const [client, setClient] = useState<ClientRepresentation>();
|
2020-11-02 20:15:09 +00:00
|
|
|
|
2021-01-29 13:59:03 +00:00
|
|
|
const loader = async () => {
|
2021-03-01 09:20:36 +00:00
|
|
|
const roles = await adminClient.clients.listRoles({ id: clientId });
|
2021-02-28 20:02:31 +00:00
|
|
|
return _.sortBy(roles, (role) => role.name?.toUpperCase());
|
2021-01-29 13:59:03 +00:00
|
|
|
};
|
|
|
|
|
2020-11-02 20:15:09 +00:00
|
|
|
const [toggleDeleteDialog, DeleteConfirm] = useConfirmDialog({
|
|
|
|
titleKey: "clients:clientDeleteConfirmTitle",
|
|
|
|
messageKey: "clients:clientDeleteConfirm",
|
|
|
|
continueButtonLabel: "common:delete",
|
|
|
|
continueButtonVariant: ButtonVariant.danger,
|
2020-11-12 12:55:52 +00:00
|
|
|
onConfirm: async () => {
|
2020-11-02 20:15:09 +00:00
|
|
|
try {
|
2021-03-01 09:20:36 +00:00
|
|
|
await adminClient.clients.del({ id: clientId });
|
2020-11-02 20:15:09 +00:00
|
|
|
addAlert(t("clientDeletedSuccess"), AlertVariant.success);
|
2021-04-12 15:42:36 +00:00
|
|
|
history.push(`/${realm}/clients`);
|
2020-11-02 20:15:09 +00:00
|
|
|
} catch (error) {
|
|
|
|
addAlert(`${t("clientDeleteError")} ${error}`, AlertVariant.danger);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
const setupForm = (client: ClientRepresentation) => {
|
2021-02-28 20:02:31 +00:00
|
|
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
|
|
const { redirectUris, webOrigins, ...formValues } = client;
|
|
|
|
form.reset(formValues);
|
2020-11-02 20:15:09 +00:00
|
|
|
Object.entries(client).map((entry) => {
|
2021-02-23 08:55:24 +00:00
|
|
|
if (entry[0] === "redirectUris" || entry[0] === "webOrigins") {
|
2020-11-02 20:15:09 +00:00
|
|
|
form.setValue(entry[0], convertToMultiline(entry[1]));
|
|
|
|
} else if (entry[0] === "attributes") {
|
|
|
|
convertToFormValues(entry[1], "attributes", form.setValue);
|
|
|
|
} else {
|
|
|
|
form.setValue(entry[0], entry[1]);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2021-04-29 06:28:59 +00:00
|
|
|
useFetch(
|
|
|
|
() => adminClient.clients.findOne({ id: clientId }),
|
|
|
|
(fetchedClient) => {
|
|
|
|
setClient(fetchedClient);
|
|
|
|
setupForm(fetchedClient);
|
|
|
|
},
|
|
|
|
[clientId]
|
|
|
|
);
|
2020-11-02 20:15:09 +00:00
|
|
|
|
2021-03-17 13:40:19 +00:00
|
|
|
const save = async (
|
|
|
|
{ confirmed = false, messageKey = "clientSaveSuccess" }: SaveOptions = {
|
|
|
|
confirmed: false,
|
|
|
|
messageKey: "clientSaveSuccess",
|
|
|
|
}
|
|
|
|
) => {
|
2020-11-02 20:15:09 +00:00
|
|
|
if (await form.trigger()) {
|
2021-03-17 07:10:30 +00:00
|
|
|
if (
|
2021-04-06 18:14:56 +00:00
|
|
|
!client?.publicClient &&
|
2021-04-29 06:28:59 +00:00
|
|
|
client?.clientAuthenticatorType !== clientAuthenticatorType &&
|
2021-03-17 07:10:30 +00:00
|
|
|
!confirmed
|
|
|
|
) {
|
|
|
|
toggleChangeAuthenticator();
|
|
|
|
return;
|
|
|
|
}
|
2020-11-02 20:15:09 +00:00
|
|
|
const redirectUris = toValue(form.getValues()["redirectUris"]);
|
2021-02-23 08:55:24 +00:00
|
|
|
const webOrigins = toValue(form.getValues()["webOrigins"]);
|
2021-02-28 20:02:31 +00:00
|
|
|
const attributes = convertFormValuesToObject(
|
|
|
|
form.getValues()["attributes"]
|
|
|
|
);
|
2020-11-02 20:15:09 +00:00
|
|
|
|
|
|
|
try {
|
2021-02-28 20:02:31 +00:00
|
|
|
const newClient: ClientRepresentation = {
|
|
|
|
...client,
|
2020-11-02 20:15:09 +00:00
|
|
|
...form.getValues(),
|
|
|
|
redirectUris,
|
2021-02-23 08:55:24 +00:00
|
|
|
webOrigins,
|
2020-11-02 20:15:09 +00:00
|
|
|
attributes,
|
|
|
|
};
|
2021-03-01 09:20:36 +00:00
|
|
|
await adminClient.clients.update({ id: clientId }, newClient);
|
2021-02-28 20:02:31 +00:00
|
|
|
setupForm(newClient);
|
|
|
|
setClient(newClient);
|
2021-03-17 13:40:19 +00:00
|
|
|
addAlert(t(messageKey), AlertVariant.success);
|
2020-11-02 20:15:09 +00:00
|
|
|
} catch (error) {
|
|
|
|
addAlert(`${t("clientSaveError")} '${error}'`, AlertVariant.danger);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2020-11-30 19:33:31 +00:00
|
|
|
if (!client) {
|
|
|
|
return (
|
|
|
|
<div className="pf-u-text-align-center">
|
|
|
|
<Spinner />
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
2020-11-02 20:15:09 +00:00
|
|
|
return (
|
|
|
|
<>
|
2021-03-17 07:10:30 +00:00
|
|
|
<ConfirmDialogModal
|
|
|
|
continueButtonLabel="common:yes"
|
|
|
|
titleKey={t("changeAuthenticatorConfirmTitle", {
|
2021-04-29 06:28:59 +00:00
|
|
|
clientAuthenticatorType: clientAuthenticatorType,
|
2021-03-17 07:10:30 +00:00
|
|
|
})}
|
|
|
|
open={changeAuthenticatorOpen}
|
|
|
|
toggleDialog={toggleChangeAuthenticator}
|
2021-03-17 13:40:19 +00:00
|
|
|
onConfirm={() => save({ confirmed: true })}
|
2021-03-17 07:10:30 +00:00
|
|
|
>
|
|
|
|
<>
|
|
|
|
{t("changeAuthenticatorConfirm", {
|
2021-04-29 06:28:59 +00:00
|
|
|
clientAuthenticatorType: clientAuthenticatorType,
|
2021-03-17 07:10:30 +00:00
|
|
|
})}
|
2021-04-29 06:28:59 +00:00
|
|
|
{clientAuthenticatorType === "client-jwt" && (
|
2021-03-17 07:10:30 +00:00
|
|
|
<Alert variant="info" isInline title={t("signedJWTConfirm")} />
|
|
|
|
)}
|
|
|
|
</>
|
|
|
|
</ConfirmDialogModal>
|
2020-11-02 20:15:09 +00:00
|
|
|
<DeleteConfirm />
|
2021-02-28 20:02:31 +00:00
|
|
|
<DownloadDialog
|
|
|
|
id={client.id!}
|
|
|
|
protocol={client.protocol}
|
|
|
|
open={downloadDialogOpen}
|
|
|
|
toggleDialog={toggleDownloadDialog}
|
|
|
|
/>
|
2020-11-02 20:15:09 +00:00
|
|
|
<Controller
|
|
|
|
name="enabled"
|
|
|
|
control={form.control}
|
|
|
|
defaultValue={true}
|
2020-11-30 19:33:31 +00:00
|
|
|
render={({ onChange, value }) => (
|
|
|
|
<ClientDetailHeader
|
|
|
|
value={value}
|
|
|
|
onChange={onChange}
|
|
|
|
client={client}
|
|
|
|
save={save}
|
|
|
|
toggleDeleteDialog={toggleDeleteDialog}
|
|
|
|
toggleDownloadDialog={toggleDownloadDialog}
|
|
|
|
/>
|
|
|
|
)}
|
2020-11-02 20:15:09 +00:00
|
|
|
/>
|
2021-03-19 07:49:33 +00:00
|
|
|
<PageSection variant="light" className="pf-u-p-0">
|
2021-02-28 20:02:31 +00:00
|
|
|
<FormProvider {...form}>
|
2021-03-31 13:16:58 +00:00
|
|
|
<KeycloakTabs isBox>
|
2020-11-02 20:15:09 +00:00
|
|
|
<Tab
|
2021-02-28 20:02:31 +00:00
|
|
|
id="settings"
|
|
|
|
eventKey="settings"
|
|
|
|
title={<TabTitleText>{t("common:settings")}</TabTitleText>}
|
2020-11-02 20:15:09 +00:00
|
|
|
>
|
2021-03-19 07:49:33 +00:00
|
|
|
<ClientSettings
|
|
|
|
save={() => save()}
|
|
|
|
reset={() => setupForm(client)}
|
|
|
|
/>
|
2020-11-02 20:15:09 +00:00
|
|
|
</Tab>
|
2021-05-04 08:11:58 +00:00
|
|
|
{!client.publicClient && (
|
|
|
|
<Tab
|
|
|
|
id="keys"
|
|
|
|
eventKey="keys"
|
|
|
|
title={<TabTitleText>{t("keys")}</TabTitleText>}
|
|
|
|
>
|
|
|
|
<Keys clientId={clientId} save={() => save()} />
|
|
|
|
</Tab>
|
|
|
|
)}
|
2021-04-06 18:14:56 +00:00
|
|
|
{!client.publicClient && (
|
2020-11-30 19:33:31 +00:00
|
|
|
<Tab
|
2021-02-28 20:02:31 +00:00
|
|
|
id="credentials"
|
|
|
|
eventKey="credentials"
|
|
|
|
title={<TabTitleText>{t("credentials")}</TabTitleText>}
|
2020-11-30 19:33:31 +00:00
|
|
|
>
|
2021-03-17 13:40:19 +00:00
|
|
|
<Credentials clientId={clientId} save={() => save()} />
|
2020-11-30 19:33:31 +00:00
|
|
|
</Tab>
|
2021-02-28 20:02:31 +00:00
|
|
|
)}
|
|
|
|
<Tab
|
|
|
|
id="roles"
|
|
|
|
eventKey="roles"
|
|
|
|
title={<TabTitleText>{t("roles")}</TabTitleText>}
|
|
|
|
>
|
2021-03-15 13:42:19 +00:00
|
|
|
<RolesList
|
|
|
|
loader={loader}
|
|
|
|
paginated={false}
|
|
|
|
messageBundle="clients"
|
|
|
|
/>
|
2021-02-28 20:02:31 +00:00
|
|
|
</Tab>
|
|
|
|
<Tab
|
|
|
|
id="clientScopes"
|
|
|
|
eventKey="clientScopes"
|
|
|
|
title={<TabTitleText>{t("clientScopes")}</TabTitleText>}
|
|
|
|
>
|
2021-03-01 09:20:36 +00:00
|
|
|
<Tabs
|
|
|
|
activeKey={activeTab2}
|
|
|
|
onSelect={(_, key) => setActiveTab2(key as number)}
|
|
|
|
>
|
2021-02-28 20:02:31 +00:00
|
|
|
<Tab
|
|
|
|
id="setup"
|
2021-03-01 09:20:36 +00:00
|
|
|
eventKey={30}
|
2021-02-28 20:02:31 +00:00
|
|
|
title={<TabTitleText>{t("setup")}</TabTitleText>}
|
|
|
|
>
|
2021-03-01 09:20:36 +00:00
|
|
|
<ClientScopes
|
|
|
|
clientId={clientId}
|
|
|
|
protocol={client!.protocol!}
|
|
|
|
/>
|
2021-02-28 20:02:31 +00:00
|
|
|
</Tab>
|
|
|
|
<Tab
|
|
|
|
id="evaluate"
|
2021-03-01 09:20:36 +00:00
|
|
|
eventKey={31}
|
2021-02-28 20:02:31 +00:00
|
|
|
title={<TabTitleText>{t("evaluate")}</TabTitleText>}
|
|
|
|
>
|
2021-03-01 09:20:36 +00:00
|
|
|
<EvaluateScopes
|
|
|
|
clientId={clientId}
|
|
|
|
protocol={client!.protocol!}
|
|
|
|
/>
|
2021-02-28 20:02:31 +00:00
|
|
|
</Tab>
|
2021-03-01 09:20:36 +00:00
|
|
|
</Tabs>
|
2021-02-28 20:02:31 +00:00
|
|
|
</Tab>
|
|
|
|
{client!.serviceAccountsEnabled && (
|
2020-11-24 20:11:13 +00:00
|
|
|
<Tab
|
2021-02-28 20:02:31 +00:00
|
|
|
id="serviceAccount"
|
|
|
|
eventKey="serviceAccount"
|
|
|
|
title={<TabTitleText>{t("serviceAccount")}</TabTitleText>}
|
2020-11-24 20:11:13 +00:00
|
|
|
>
|
2021-03-01 09:20:36 +00:00
|
|
|
<ServiceAccount clientId={clientId} />
|
2020-11-24 20:11:13 +00:00
|
|
|
</Tab>
|
2021-02-28 20:02:31 +00:00
|
|
|
)}
|
2020-12-07 18:37:36 +00:00
|
|
|
<Tab
|
2021-02-28 20:02:31 +00:00
|
|
|
id="advanced"
|
|
|
|
eventKey="advanced"
|
|
|
|
title={<TabTitleText>{t("advanced")}</TabTitleText>}
|
2020-12-07 18:37:36 +00:00
|
|
|
>
|
2021-02-28 20:02:31 +00:00
|
|
|
<AdvancedTab save={save} client={client} />
|
2020-12-07 18:37:36 +00:00
|
|
|
</Tab>
|
2021-02-28 20:02:31 +00:00
|
|
|
</KeycloakTabs>
|
|
|
|
</FormProvider>
|
2020-11-02 20:15:09 +00:00
|
|
|
</PageSection>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
};
|