2020-11-12 12:55:52 +00:00
|
|
|
import React, { useEffect, useState } from "react";
|
2020-11-02 20:15:09 +00:00
|
|
|
import {
|
|
|
|
AlertVariant,
|
|
|
|
ButtonVariant,
|
|
|
|
DropdownItem,
|
|
|
|
PageSection,
|
2020-11-30 19:33:31 +00:00
|
|
|
Spinner,
|
2020-11-02 20:15:09 +00:00
|
|
|
Tab,
|
|
|
|
TabTitleText,
|
|
|
|
} from "@patternfly/react-core";
|
2021-02-17 21:12:25 +00:00
|
|
|
import { useParams } from "react-router-dom";
|
|
|
|
import { useErrorHandler } from "react-error-boundary";
|
2020-11-02 20:15:09 +00:00
|
|
|
import { useTranslation } from "react-i18next";
|
|
|
|
import { Controller, useForm, useWatch } from "react-hook-form";
|
2020-11-12 12:55:52 +00:00
|
|
|
import ClientRepresentation from "keycloak-admin/lib/defs/clientRepresentation";
|
2020-11-02 20:15:09 +00:00
|
|
|
|
|
|
|
import { ClientSettings } from "./ClientSettings";
|
|
|
|
import { useAlerts } from "../components/alert/Alerts";
|
|
|
|
import { useConfirmDialog } from "../components/confirm-dialog/ConfirmDialog";
|
|
|
|
import { useDownloadDialog } from "../components/download-dialog/DownloadDialog";
|
|
|
|
import { ViewHeader } from "../components/view-header/ViewHeader";
|
2021-01-11 18:56:19 +00:00
|
|
|
import { useAdminClient, asyncStateFetch } 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,
|
|
|
|
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";
|
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"
|
|
|
|
dropdownItems={[
|
|
|
|
<DropdownItem key="download" onClick={() => toggleDownloadDialog()}>
|
|
|
|
{t("downloadAdapterConfig")}
|
|
|
|
</DropdownItem>,
|
|
|
|
<DropdownItem key="export" onClick={() => exportClient(client)}>
|
|
|
|
{t("common:export")}
|
|
|
|
</DropdownItem>,
|
|
|
|
<DropdownItem key="delete" onClick={() => toggleDeleteDialog()}>
|
|
|
|
{t("common:delete")}
|
|
|
|
</DropdownItem>,
|
|
|
|
]}
|
|
|
|
isEnabled={value}
|
|
|
|
onToggle={(value) => {
|
|
|
|
if (!value) {
|
|
|
|
toggleDisableDialog();
|
|
|
|
} else {
|
|
|
|
onChange(value);
|
|
|
|
save();
|
|
|
|
}
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
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-02-17 21:12:25 +00:00
|
|
|
const handleError = useErrorHandler();
|
|
|
|
|
2020-11-02 20:15:09 +00:00
|
|
|
const { addAlert } = useAlerts();
|
|
|
|
|
|
|
|
const form = useForm();
|
|
|
|
const publicClient = useWatch({
|
|
|
|
control: form.control,
|
|
|
|
name: "publicClient",
|
|
|
|
defaultValue: false,
|
|
|
|
});
|
2020-12-07 18:37:36 +00:00
|
|
|
|
2020-11-02 20:15:09 +00:00
|
|
|
const { id } = useParams<{ id: string }>();
|
|
|
|
|
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-01-31 18:07:06 +00:00
|
|
|
const roles = await adminClient.clients.listRoles({ id });
|
|
|
|
return roles.sort((r1, r2) => {
|
|
|
|
const r1Name = r1.name?.toUpperCase();
|
|
|
|
const r2Name = r2.name?.toUpperCase();
|
|
|
|
if (r1Name! < r2Name!) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (r1Name! > r2Name!) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
});
|
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 {
|
2020-11-12 12:55:52 +00:00
|
|
|
await adminClient.clients.del({ id });
|
2020-11-02 20:15:09 +00:00
|
|
|
addAlert(t("clientDeletedSuccess"), AlertVariant.success);
|
|
|
|
} catch (error) {
|
|
|
|
addAlert(`${t("clientDeleteError")} ${error}`, AlertVariant.danger);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
const [toggleDownloadDialog, DownloadDialog] = useDownloadDialog({
|
|
|
|
id,
|
|
|
|
protocol: form.getValues("protocol"),
|
|
|
|
});
|
|
|
|
|
|
|
|
const setupForm = (client: ClientRepresentation) => {
|
|
|
|
form.reset(client);
|
|
|
|
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]);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
useEffect(() => {
|
2021-01-11 18:56:19 +00:00
|
|
|
return asyncStateFetch(
|
2021-01-05 13:39:27 +00:00
|
|
|
() => adminClient.clients.findOne({ id }),
|
|
|
|
(fetchedClient) => {
|
2020-11-24 20:11:13 +00:00
|
|
|
setClient(fetchedClient);
|
2020-11-12 12:55:52 +00:00
|
|
|
setupForm(fetchedClient);
|
2021-02-17 21:12:25 +00:00
|
|
|
},
|
|
|
|
handleError
|
2021-01-05 13:39:27 +00:00
|
|
|
);
|
2020-11-02 20:15:09 +00:00
|
|
|
}, []);
|
|
|
|
|
|
|
|
const save = async () => {
|
|
|
|
if (await form.trigger()) {
|
|
|
|
const redirectUris = toValue(form.getValues()["redirectUris"]);
|
2021-02-23 08:55:24 +00:00
|
|
|
const webOrigins = toValue(form.getValues()["webOrigins"]);
|
2020-11-02 20:15:09 +00:00
|
|
|
const attributes = form.getValues()["attributes"]
|
|
|
|
? convertFormValuesToObject(form.getValues()["attributes"])
|
|
|
|
: {};
|
|
|
|
|
|
|
|
try {
|
|
|
|
const client = {
|
|
|
|
...form.getValues(),
|
|
|
|
redirectUris,
|
2021-02-23 08:55:24 +00:00
|
|
|
webOrigins,
|
2020-11-02 20:15:09 +00:00
|
|
|
attributes,
|
|
|
|
};
|
2020-11-12 12:55:52 +00:00
|
|
|
await adminClient.clients.update({ id }, client);
|
2020-11-02 20:15:09 +00:00
|
|
|
setupForm(client as ClientRepresentation);
|
2020-12-07 18:37:36 +00:00
|
|
|
setClient(client);
|
2020-11-02 20:15:09 +00:00
|
|
|
addAlert(t("clientSaveSuccess"), AlertVariant.success);
|
|
|
|
} 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 (
|
|
|
|
<>
|
|
|
|
<DeleteConfirm />
|
|
|
|
<DownloadDialog />
|
|
|
|
<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
|
|
|
/>
|
|
|
|
<PageSection variant="light">
|
2021-01-13 20:47:40 +00:00
|
|
|
<KeycloakTabs isBox>
|
2020-11-02 20:15:09 +00:00
|
|
|
<Tab
|
2021-01-13 20:47:40 +00:00
|
|
|
eventKey="settings"
|
2020-12-08 06:30:53 +00:00
|
|
|
title={<TabTitleText>{t("common:settings")}</TabTitleText>}
|
2020-11-02 20:15:09 +00:00
|
|
|
>
|
|
|
|
<ClientSettings form={form} save={save} />
|
|
|
|
</Tab>
|
|
|
|
{publicClient && (
|
|
|
|
<Tab
|
2021-01-13 20:47:40 +00:00
|
|
|
eventKey="credentials"
|
2020-11-02 20:15:09 +00:00
|
|
|
title={<TabTitleText>{t("credentials")}</TabTitleText>}
|
|
|
|
>
|
|
|
|
<Credentials clientId={id} form={form} save={save} />
|
|
|
|
</Tab>
|
|
|
|
)}
|
2021-01-29 13:59:03 +00:00
|
|
|
<Tab
|
|
|
|
eventKey="roles"
|
|
|
|
title={<TabTitleText>{t("roles")}</TabTitleText>}
|
|
|
|
>
|
|
|
|
<RolesList loader={loader} paginated={false} />
|
|
|
|
</Tab>
|
2020-11-24 20:11:13 +00:00
|
|
|
<Tab
|
2021-01-13 20:47:40 +00:00
|
|
|
eventKey="clientScopes"
|
2020-11-24 20:11:13 +00:00
|
|
|
title={<TabTitleText>{t("clientScopes")}</TabTitleText>}
|
|
|
|
>
|
2021-01-13 20:47:40 +00:00
|
|
|
<KeycloakTabs paramName="subtab" isSecondary>
|
2020-11-30 19:33:31 +00:00
|
|
|
<Tab
|
2021-01-13 20:47:40 +00:00
|
|
|
eventKey="setup"
|
2020-11-30 19:33:31 +00:00
|
|
|
title={<TabTitleText>{t("setup")}</TabTitleText>}
|
|
|
|
>
|
|
|
|
<ClientScopes clientId={id} protocol={client!.protocol!} />
|
|
|
|
</Tab>
|
2020-11-24 20:11:13 +00:00
|
|
|
<Tab
|
2021-01-13 20:47:40 +00:00
|
|
|
eventKey="evaluate"
|
2020-11-24 20:11:13 +00:00
|
|
|
title={<TabTitleText>{t("evaluate")}</TabTitleText>}
|
|
|
|
>
|
2021-01-12 13:16:35 +00:00
|
|
|
<EvaluateScopes clientId={id} protocol={client!.protocol!} />
|
2020-11-24 20:11:13 +00:00
|
|
|
</Tab>
|
2021-01-13 20:47:40 +00:00
|
|
|
</KeycloakTabs>
|
2020-11-24 20:11:13 +00:00
|
|
|
</Tab>
|
2020-12-07 18:37:36 +00:00
|
|
|
{client && client.serviceAccountsEnabled && (
|
|
|
|
<Tab
|
2021-01-13 20:47:40 +00:00
|
|
|
eventKey="serviceAccount"
|
2020-12-07 18:37:36 +00:00
|
|
|
title={<TabTitleText>{t("serviceAccount")}</TabTitleText>}
|
|
|
|
>
|
|
|
|
<ServiceAccount clientId={id} />
|
|
|
|
</Tab>
|
|
|
|
)}
|
2021-01-13 20:47:40 +00:00
|
|
|
</KeycloakTabs>
|
2020-11-02 20:15:09 +00:00
|
|
|
</PageSection>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
};
|