Skip to content

Commit

Permalink
added acr loa map field to realm settings
Browse files Browse the repository at this point in the history
fixes: #2668
  • Loading branch information
edewit committed Jun 13, 2022
1 parent f775fd6 commit 75a2f0f
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/realm-settings/GeneralTab.tsx
Expand Up @@ -24,6 +24,7 @@ import { FormAccess } from "../components/form-access/FormAccess";
import { HelpItem } from "../components/help-enabler/HelpItem";
import { FormattedLink } from "../components/external-link/FormattedLink";
import { KeycloakTextInput } from "../components/keycloak-text-input/KeycloakTextInput";
import { KeyValueInput } from "../components/key-value-form/KeyValueInput";

type RealmSettingsGeneralTabProps = {
save: (realm: RealmRepresentation) => void;
Expand Down Expand Up @@ -143,6 +144,18 @@ export const RealmSettingsGeneralTab = ({
)}
/>
</FormGroup>
<FormGroup
label={t("clients:acrToLoAMapping")}
fieldId="acrToLoAMapping"
labelIcon={
<HelpItem
helpText="clients-help:acrToLoAMapping"
fieldLabelId="clients:acrToLoAMapping"
/>
}
>
<KeyValueInput name="attributes.acr.loa.map" />
</FormGroup>
<FormGroup
hasNoPaddingTop
label={t("userManagedAccess")}
Expand Down
19 changes: 19 additions & 0 deletions src/realm-settings/RealmSettingsTabs.tsx
Expand Up @@ -54,6 +54,7 @@ import useIsFeatureEnabled, { Feature } from "../utils/useIsFeatureEnabled";
import { ClientPoliciesTab, toClientPolicies } from "./routes/ClientPolicies";
import { KeysTab } from "./keys/KeysTab";
import { DEFAULT_LOCALE } from "../i18n";
import type { KeyValueType } from "../components/key-value-form/key-value-convert";

type RealmSettingsHeaderProps = {
onChange: (value: boolean) => void;
Expand Down Expand Up @@ -187,6 +188,15 @@ export const RealmSettingsTabs = ({

const setupForm = (r: RealmRepresentation = realm) => {
convertToFormValues(r, setValue);
if (r.attributes?.["acr.loa.map"]) {
form.setValue(
"attributes.acr.loa.map",
Object.entries(JSON.parse(r.attributes["acr.loa.map"])).flatMap(
([key, value]) => ({ key, value })
)
);
}

if (r.supportedLocales?.length === 0) {
setValue("supportedLocales", [DEFAULT_LOCALE]);
}
Expand All @@ -200,6 +210,15 @@ export const RealmSettingsTabs = ({
const save = async (realm: RealmRepresentation) => {
try {
realm = convertFormValuesToObject(realm);
if (realm.attributes?.["acr.loa.map"]) {
realm.attributes["acr.loa.map"] = JSON.stringify(
Object.fromEntries(
(realm.attributes["acr.loa.map"] as KeyValueType[])
.filter(({ key }) => key !== "")
.map(({ key, value }) => [key, value])
)
);
}

await adminClient.realms.update(
{ realm: realmName },
Expand Down

0 comments on commit 75a2f0f

Please sign in to comment.