Merge pull request #547 from edewit/authorisation-authentication

fixing PR comment:
This commit is contained in:
xianli123 2021-04-26 20:48:30 +08:00 committed by GitHub
commit 6cf2d50e0e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 36 additions and 15 deletions

View file

@ -1,5 +1,6 @@
import React from "react"; import React from "react";
import { useTranslation } from "react-i18next"; import { useTranslation } from "react-i18next";
import { Controller, useFormContext } from "react-hook-form";
import { import {
FormGroup, FormGroup,
Switch, Switch,
@ -8,11 +9,13 @@ import {
GridItem, GridItem,
InputGroup, InputGroup,
} from "@patternfly/react-core"; } from "@patternfly/react-core";
import { Controller, useFormContext } from "react-hook-form";
import { FormAccess } from "../../components/form-access/FormAccess"; import { FormAccess } from "../../components/form-access/FormAccess";
import { ClientForm } from "../ClientDetails"; import { ClientForm } from "../ClientDetails";
import { HelpItem } from "../../components/help-enabler/HelpItem"; import { HelpItem } from "../../components/help-enabler/HelpItem";
import "./capability-config.css";
type CapabilityConfigProps = { type CapabilityConfigProps = {
unWrap?: boolean; unWrap?: boolean;
protocol?: string; protocol?: string;
@ -26,10 +29,15 @@ export const CapabilityConfig = ({
const { control, watch, setValue } = useFormContext<ClientForm>(); const { control, watch, setValue } = useFormContext<ClientForm>();
const protocol = type || watch("protocol"); const protocol = type || watch("protocol");
const clientAuthentication = watch("publicClient"); const clientAuthentication = watch("publicClient");
const clientAuthorization = watch("authorizationServicesEnabled"); const authorization = watch("authorizationServicesEnabled");
return ( return (
<FormAccess isHorizontal role="manage-clients" unWrap={unWrap}> <FormAccess
isHorizontal
role="manage-clients"
unWrap={unWrap}
className="keycloak__capability-config__form"
>
<> <>
{protocol === "openid-connect" && ( {protocol === "openid-connect" && (
<> <>
@ -47,7 +55,7 @@ export const CapabilityConfig = ({
> >
<Controller <Controller
name="publicClient" name="publicClient"
defaultValue={true} defaultValue={false}
control={control} control={control}
render={({ onChange, value }) => ( render={({ onChange, value }) => (
<Switch <Switch
@ -57,7 +65,13 @@ export const CapabilityConfig = ({
label={t("common:on")} label={t("common:on")}
labelOff={t("common:off")} labelOff={t("common:off")}
isChecked={!value} isChecked={!value}
onChange={(value) => onChange(!value)} onChange={(value) => {
onChange(!value);
if (!value) {
setValue("authorizationServicesEnabled", false);
setValue("serviceAccountsEnabled", false);
}
}}
/> />
)} )}
/> />
@ -85,7 +99,7 @@ export const CapabilityConfig = ({
name="authorizationServicesEnabled" name="authorizationServicesEnabled"
label={t("common:on")} label={t("common:on")}
labelOff={t("common:off")} labelOff={t("common:off")}
isChecked={value} isChecked={value && !clientAuthentication}
onChange={(value) => { onChange={(value) => {
onChange(value); onChange(value);
if (value) { if (value) {
@ -103,7 +117,7 @@ export const CapabilityConfig = ({
fieldId="kc-flow" fieldId="kc-flow"
> >
<Grid> <Grid>
<GridItem lg={3} sm={6}> <GridItem lg={4} sm={6}>
<Controller <Controller
name="standardFlowEnabled" name="standardFlowEnabled"
defaultValue={true} defaultValue={true}
@ -127,7 +141,7 @@ export const CapabilityConfig = ({
)} )}
/> />
</GridItem> </GridItem>
<GridItem lg={9} sm={6}> <GridItem lg={8} sm={6}>
<Controller <Controller
name="directAccessGrantsEnabled" name="directAccessGrantsEnabled"
defaultValue={true} defaultValue={true}
@ -151,7 +165,7 @@ export const CapabilityConfig = ({
)} )}
/> />
</GridItem> </GridItem>
<GridItem lg={3} sm={6}> <GridItem lg={4} sm={6}>
<Controller <Controller
name="implicitFlowEnabled" name="implicitFlowEnabled"
defaultValue={false} defaultValue={false}
@ -175,7 +189,7 @@ export const CapabilityConfig = ({
)} )}
/> />
</GridItem> </GridItem>
<GridItem lg={9} sm={6}> <GridItem lg={8} sm={6}>
<Controller <Controller
name="serviceAccountsEnabled" name="serviceAccountsEnabled"
defaultValue={false} defaultValue={false}
@ -187,10 +201,13 @@ export const CapabilityConfig = ({
label={t("serviceAccount")} label={t("serviceAccount")}
id="kc-flow-service-account" id="kc-flow-service-account"
name="serviceAccountsEnabled" name="serviceAccountsEnabled"
isChecked={value} isChecked={
value || (clientAuthentication && authorization)
}
onChange={onChange} onChange={onChange}
isDisabled={ isDisabled={
!clientAuthentication || clientAuthorization (clientAuthentication && !authorization) ||
(!clientAuthentication && authorization)
} }
/> />
<HelpItem <HelpItem

View file

@ -7,7 +7,6 @@ import {
WizardFooter, WizardFooter,
WizardContextConsumer, WizardContextConsumer,
Button, Button,
WizardStepFunctionType,
} from "@patternfly/react-core"; } from "@patternfly/react-core";
import { useTranslation } from "react-i18next"; import { useTranslation } from "react-i18next";
import { FormProvider, useForm } from "react-hook-form"; import { FormProvider, useForm } from "react-hook-form";

View file

@ -0,0 +1,5 @@
@media (min-width: 768px) {
.keycloak__capability-config__form .pf-c-form__group {
--pf-c-form--m-horizontal__group-label--md--GridColumnWidth: 10rem;
}
}

View file

@ -103,8 +103,8 @@
"authentication": "Authentication", "authentication": "Authentication",
"authenticationFlow": "Authentication flow", "authenticationFlow": "Authentication flow",
"standardFlow": "Standard flow", "standardFlow": "Standard flow",
"directAccess": "Direct access", "directAccess": "Direct access grants",
"serviceAccount": "Service account roles", "serviceAccount": "Service accounts",
"enableServiceAccount": "Enable service account roles", "enableServiceAccount": "Enable service account roles",
"assignRolesTo": "Assign roles to {{client}} account", "assignRolesTo": "Assign roles to {{client}} account",
"searchByRoleName": "Search by role name", "searchByRoleName": "Search by role name",