From 0f31fa3128cd6d8a408bd0faf45def7e9fe8e9c9 Mon Sep 17 00:00:00 2001 From: = Date: Fri, 14 Mar 2025 22:10:23 +0530 Subject: [PATCH] feat: updated form for oidc auth --- frontend/src/hooks/api/admin/queries.ts | 2 +- .../src/hooks/api/identities/mutations.tsx | 8 +- frontend/src/hooks/api/identities/types.ts | 3 + .../pages/admin/OverviewPage/OverviewPage.tsx | 2 +- .../IdentitySection/IdentityOidcAuthForm.tsx | 104 ++++++++++++++++++ .../ViewIdentityOidcAuthContent.tsx | 20 ++++ .../components/SecretListView/SecretItem.tsx | 5 +- 7 files changed, 139 insertions(+), 5 deletions(-) diff --git a/frontend/src/hooks/api/admin/queries.ts b/frontend/src/hooks/api/admin/queries.ts index 496990abe..b24841dbd 100644 --- a/frontend/src/hooks/api/admin/queries.ts +++ b/frontend/src/hooks/api/admin/queries.ts @@ -1,6 +1,7 @@ import { useInfiniteQuery, useQuery, UseQueryOptions } from "@tanstack/react-query"; import { apiRequest } from "@app/config/request"; +import { Identity } from "@app/hooks/api/identities/types"; import { User } from "../types"; import { @@ -10,7 +11,6 @@ import { TGetServerRootKmsEncryptionDetails, TServerConfig } from "./types"; -import { Identity } from "@app/hooks/api/identities/types"; export const adminStandaloneKeys = { getUsers: "get-users", diff --git a/frontend/src/hooks/api/identities/mutations.tsx b/frontend/src/hooks/api/identities/mutations.tsx index 3e38d9067..d68595ad5 100644 --- a/frontend/src/hooks/api/identities/mutations.tsx +++ b/frontend/src/hooks/api/identities/mutations.tsx @@ -462,6 +462,7 @@ export const useUpdateIdentityOidcAuth = () => { boundIssuer, boundAudiences, boundClaims, + claimMetadataMapping, boundSubject }) => { const { @@ -478,7 +479,8 @@ export const useUpdateIdentityOidcAuth = () => { accessTokenTTL, accessTokenMaxTTL, accessTokenNumUsesLimit, - accessTokenTrustedIps + accessTokenTrustedIps, + claimMetadataMapping } ); @@ -504,6 +506,7 @@ export const useAddIdentityOidcAuth = () => { boundIssuer, boundAudiences, boundClaims, + claimMetadataMapping, boundSubject, accessTokenTTL, accessTokenMaxTTL, @@ -524,7 +527,8 @@ export const useAddIdentityOidcAuth = () => { accessTokenTTL, accessTokenMaxTTL, accessTokenNumUsesLimit, - accessTokenTrustedIps + accessTokenTrustedIps, + claimMetadataMapping } ); diff --git a/frontend/src/hooks/api/identities/types.ts b/frontend/src/hooks/api/identities/types.ts index 8d344e7f7..9920fcf0b 100644 --- a/frontend/src/hooks/api/identities/types.ts +++ b/frontend/src/hooks/api/identities/types.ts @@ -193,6 +193,7 @@ export type IdentityOidcAuth = { boundIssuer: string; boundAudiences: string; boundClaims: Record; + claimMetadataMapping: Record; boundSubject: string; accessTokenTTL: number; accessTokenMaxTTL: number; @@ -208,6 +209,7 @@ export type AddIdentityOidcAuthDTO = { boundIssuer: string; boundAudiences: string; boundClaims: Record; + claimMetadataMapping: Record; boundSubject: string; accessTokenTTL: number; accessTokenMaxTTL: number; @@ -225,6 +227,7 @@ export type UpdateIdentityOidcAuthDTO = { boundIssuer?: string; boundAudiences?: string; boundClaims?: Record; + claimMetadataMapping?: Record; boundSubject?: string; accessTokenTTL?: number; accessTokenMaxTTL?: number; diff --git a/frontend/src/pages/admin/OverviewPage/OverviewPage.tsx b/frontend/src/pages/admin/OverviewPage/OverviewPage.tsx index 776c5e20f..8d1e25bc5 100644 --- a/frontend/src/pages/admin/OverviewPage/OverviewPage.tsx +++ b/frontend/src/pages/admin/OverviewPage/OverviewPage.tsx @@ -28,13 +28,13 @@ import { useGetServerRootKmsEncryptionDetails, useUpdateServerConfig } from "@app/hooks/api"; +import { IdentityPanel } from "@app/pages/admin/OverviewPage/components/IdentityPanel"; import { AuthPanel } from "./components/AuthPanel"; import { EncryptionPanel } from "./components/EncryptionPanel"; import { IntegrationPanel } from "./components/IntegrationPanel"; import { RateLimitPanel } from "./components/RateLimitPanel"; import { UserPanel } from "./components/UserPanel"; -import { IdentityPanel } from "@app/pages/admin/OverviewPage/components/IdentityPanel"; enum TabSections { Settings = "settings", diff --git a/frontend/src/pages/organization/AccessManagementPage/components/OrgIdentityTab/components/IdentitySection/IdentityOidcAuthForm.tsx b/frontend/src/pages/organization/AccessManagementPage/components/OrgIdentityTab/components/IdentitySection/IdentityOidcAuthForm.tsx index b1b0739cf..094be734e 100644 --- a/frontend/src/pages/organization/AccessManagementPage/components/OrgIdentityTab/components/IdentitySection/IdentityOidcAuthForm.tsx +++ b/frontend/src/pages/organization/AccessManagementPage/components/OrgIdentityTab/components/IdentitySection/IdentityOidcAuthForm.tsx @@ -52,6 +52,12 @@ const schema = z.object({ value: z.string() }) ), + claimMetadataMapping: z.array( + z.object({ + key: z.string(), + value: z.string() + }) + ), boundSubject: z.string().optional().default("") }); @@ -109,6 +115,15 @@ export const IdentityOidcAuthForm = ({ name: "boundClaims" }); + const { + fields: claimMetadataMappingFields, + append: appendClaimMetadataMappingField, + remove: removeClaimMetadataMappingField + } = useFieldArray({ + control, + name: "claimMetadataMapping" + }); + const { fields: accessTokenTrustedIpsFields, append: appendAccessTokenTrustedIp, @@ -126,6 +141,10 @@ export const IdentityOidcAuthForm = ({ key, value })), + claimMetadataMapping: Object.entries(data.claimMetadataMapping).map(([key, value]) => ({ + key, + value + })), boundSubject: data.boundSubject, accessTokenTTL: String(data.accessTokenTTL), accessTokenMaxTTL: String(data.accessTokenMaxTTL), @@ -164,6 +183,7 @@ export const IdentityOidcAuthForm = ({ boundIssuer, boundAudiences, boundClaims, + claimMetadataMapping, boundSubject }: FormData) => { try { @@ -180,6 +200,9 @@ export const IdentityOidcAuthForm = ({ boundIssuer, boundAudiences, boundClaims: Object.fromEntries(boundClaims.map((entry) => [entry.key, entry.value])), + claimMetadataMapping: Object.fromEntries( + claimMetadataMapping.map((entry) => [entry.key, entry.value]) + ), boundSubject, accessTokenTTL: Number(accessTokenTTL), accessTokenMaxTTL: Number(accessTokenMaxTTL), @@ -194,6 +217,9 @@ export const IdentityOidcAuthForm = ({ boundIssuer, boundAudiences, boundClaims: Object.fromEntries(boundClaims.map((entry) => [entry.key, entry.value])), + claimMetadataMapping: Object.fromEntries( + claimMetadataMapping.map((entry) => [entry.key, entry.value]) + ), boundSubject, organizationId: orgId, accessTokenTTL: Number(accessTokenTTL), @@ -449,6 +475,84 @@ export const IdentityOidcAuthForm = ({ Add Claims + {claimMetadataMappingFields.map(({ id }, index) => ( +
+ { + return ( + + + + ) : undefined + } + isError={Boolean(error)} + errorText={error?.message} + > + field.onChange(e)} + placeholder="property" + /> + + ); + }} + /> + { + return ( + + field.onChange(e)} + placeholder="key1.nested-key2" + /> + + ); + }} + /> + removeClaimMetadataMappingField(index)} + size="lg" + colorSchema="danger" + variant="plain" + ariaLabel="update" + className="p-3" + > + + +
+ ))} +
+ +
{accessTokenTrustedIpsFields.map(({ id }, index) => (
)} + + {Object.keys(data.claimMetadataMapping).length && ( + + {JSON.stringify(data.claimMetadataMapping, null, 2)} + + } + > +
+ + + Reveal + +
+
+ )} +
); }; diff --git a/frontend/src/pages/secret-manager/SecretDashboardPage/components/SecretListView/SecretItem.tsx b/frontend/src/pages/secret-manager/SecretDashboardPage/components/SecretListView/SecretItem.tsx index 629c23048..01d477097 100644 --- a/frontend/src/pages/secret-manager/SecretDashboardPage/components/SecretListView/SecretItem.tsx +++ b/frontend/src/pages/secret-manager/SecretDashboardPage/components/SecretListView/SecretItem.tsx @@ -306,7 +306,10 @@ export const SecretItem = memo( )} /> )} -
+