2021-04-29 06:28:59 +00:00
|
|
|
import React, { useState } from "react";
|
2021-02-28 20:02:31 +00:00
|
|
|
import { Control, Controller } from "react-hook-form";
|
|
|
|
import { useTranslation } from "react-i18next";
|
|
|
|
import _ from "lodash";
|
|
|
|
import {
|
2021-07-01 06:53:58 +00:00
|
|
|
ActionGroup,
|
|
|
|
Button,
|
2021-02-28 20:02:31 +00:00
|
|
|
FormGroup,
|
|
|
|
Select,
|
|
|
|
SelectOption,
|
|
|
|
SelectVariant,
|
|
|
|
} from "@patternfly/react-core";
|
|
|
|
|
|
|
|
import { FormAccess } from "../../components/form-access/FormAccess";
|
|
|
|
import { HelpItem } from "../../components/help-enabler/HelpItem";
|
2021-04-29 06:28:59 +00:00
|
|
|
import { useFetch, useAdminClient } from "../../context/auth/AdminClient";
|
2021-02-28 20:02:31 +00:00
|
|
|
|
|
|
|
type AuthenticationOverridesProps = {
|
|
|
|
control: Control<Record<string, any>>;
|
|
|
|
save: () => void;
|
|
|
|
reset: () => void;
|
|
|
|
protocol?: string;
|
|
|
|
};
|
|
|
|
|
|
|
|
export const AuthenticationOverrides = ({
|
|
|
|
protocol,
|
|
|
|
control,
|
|
|
|
save,
|
|
|
|
reset,
|
|
|
|
}: AuthenticationOverridesProps) => {
|
|
|
|
const adminClient = useAdminClient();
|
|
|
|
const { t } = useTranslation("clients");
|
|
|
|
const [flows, setFlows] = useState<JSX.Element[]>([]);
|
|
|
|
const [browserFlowOpen, setBrowserFlowOpen] = useState(false);
|
|
|
|
const [directGrantOpen, setDirectGrantOpen] = useState(false);
|
|
|
|
|
2021-04-29 06:28:59 +00:00
|
|
|
useFetch(
|
|
|
|
() => adminClient.authenticationManagement.getFlows(),
|
|
|
|
(flows) => {
|
|
|
|
let filteredFlows = [
|
|
|
|
...flows.filter((flow) => flow.providerId !== "client-flow"),
|
|
|
|
];
|
|
|
|
filteredFlows = _.sortBy(filteredFlows, [(f) => f.alias]);
|
|
|
|
setFlows([
|
|
|
|
<SelectOption key="empty" value="">
|
|
|
|
{t("common:choose")}
|
|
|
|
</SelectOption>,
|
|
|
|
...filteredFlows.map((flow) => (
|
|
|
|
<SelectOption key={flow.id} value={flow.id}>
|
|
|
|
{flow.alias}
|
|
|
|
</SelectOption>
|
|
|
|
)),
|
|
|
|
]);
|
|
|
|
},
|
2021-02-28 20:02:31 +00:00
|
|
|
[]
|
|
|
|
);
|
|
|
|
|
|
|
|
return (
|
|
|
|
<FormAccess role="manage-clients" isHorizontal>
|
|
|
|
<FormGroup
|
|
|
|
label={t("browserFlow")}
|
|
|
|
fieldId="browserFlow"
|
|
|
|
labelIcon={
|
|
|
|
<HelpItem
|
|
|
|
helpText="clients-help:browserFlow"
|
|
|
|
forLabel={t("browserFlow")}
|
2021-07-12 14:09:14 +00:00
|
|
|
forID={t(`common:helpLabel`, { label: t("browserFlow") })}
|
2021-02-28 20:02:31 +00:00
|
|
|
/>
|
|
|
|
}
|
|
|
|
>
|
|
|
|
<Controller
|
|
|
|
name="authenticationFlowBindingOverrides.browser"
|
|
|
|
defaultValue=""
|
|
|
|
control={control}
|
|
|
|
render={({ onChange, value }) => (
|
|
|
|
<Select
|
|
|
|
toggleId="browserFlow"
|
|
|
|
variant={SelectVariant.single}
|
|
|
|
onToggle={() => setBrowserFlowOpen(!browserFlowOpen)}
|
|
|
|
isOpen={browserFlowOpen}
|
|
|
|
onSelect={(_, value) => {
|
|
|
|
onChange(value);
|
|
|
|
setBrowserFlowOpen(false);
|
|
|
|
}}
|
|
|
|
selections={[value]}
|
|
|
|
>
|
|
|
|
{flows}
|
|
|
|
</Select>
|
|
|
|
)}
|
|
|
|
/>
|
|
|
|
</FormGroup>
|
|
|
|
{protocol === "openid-connect" && (
|
|
|
|
<FormGroup
|
|
|
|
label={t("directGrant")}
|
|
|
|
fieldId="directGrant"
|
|
|
|
labelIcon={
|
|
|
|
<HelpItem
|
|
|
|
helpText="clients-help:directGrant"
|
|
|
|
forLabel={t("directGrant")}
|
2021-07-12 14:09:14 +00:00
|
|
|
forID={t(`common:helpLabel`, { label: t("directGrant") })}
|
2021-02-28 20:02:31 +00:00
|
|
|
/>
|
|
|
|
}
|
|
|
|
>
|
|
|
|
<Controller
|
|
|
|
name="authenticationFlowBindingOverrides.direct_grant"
|
|
|
|
defaultValue=""
|
|
|
|
control={control}
|
|
|
|
render={({ onChange, value }) => (
|
|
|
|
<Select
|
|
|
|
toggleId="directGrant"
|
|
|
|
variant={SelectVariant.single}
|
|
|
|
onToggle={() => setDirectGrantOpen(!directGrantOpen)}
|
|
|
|
isOpen={directGrantOpen}
|
|
|
|
onSelect={(_, value) => {
|
|
|
|
onChange(value);
|
|
|
|
setDirectGrantOpen(false);
|
|
|
|
}}
|
|
|
|
selections={[value]}
|
|
|
|
>
|
|
|
|
{flows}
|
|
|
|
</Select>
|
|
|
|
)}
|
|
|
|
/>
|
|
|
|
</FormGroup>
|
|
|
|
)}
|
2021-07-01 06:53:58 +00:00
|
|
|
<ActionGroup>
|
|
|
|
<Button variant="tertiary" onClick={save}>
|
|
|
|
{t("common:save")}
|
|
|
|
</Button>
|
|
|
|
<Button variant="link" onClick={reset}>
|
|
|
|
{t("common:revert")}
|
|
|
|
</Button>
|
|
|
|
</ActionGroup>
|
2021-02-28 20:02:31 +00:00
|
|
|
</FormAccess>
|
|
|
|
);
|
|
|
|
};
|