refactor: simplify authentication form submission logic across multiple identity sections

This commit is contained in:
Victor Santos
2025-10-31 19:23:32 -03:00
parent b26fb73053
commit eba04e4278
12 changed files with 468 additions and 567 deletions
@@ -137,45 +137,38 @@ export const IdentityAliCloudAuthForm = ({
accessTokenNumUsesLimit, accessTokenNumUsesLimit,
accessTokenTrustedIps accessTokenTrustedIps
}: FormData) => { }: FormData) => {
try { if (!identityId) return;
if (!identityId) return;
if (data) { if (data) {
await updateMutateAsync({ await updateMutateAsync({
organizationId: orgId, organizationId: orgId,
allowedArns, allowedArns,
identityId, identityId,
accessTokenTTL: Number(accessTokenTTL), accessTokenTTL: Number(accessTokenTTL),
accessTokenMaxTTL: Number(accessTokenMaxTTL), accessTokenMaxTTL: Number(accessTokenMaxTTL),
accessTokenNumUsesLimit: Number(accessTokenNumUsesLimit), accessTokenNumUsesLimit: Number(accessTokenNumUsesLimit),
accessTokenTrustedIps accessTokenTrustedIps
});
} else {
await addMutateAsync({
organizationId: orgId,
identityId,
allowedArns,
accessTokenTTL: Number(accessTokenTTL),
accessTokenMaxTTL: Number(accessTokenMaxTTL),
accessTokenNumUsesLimit: Number(accessTokenNumUsesLimit),
accessTokenTrustedIps
});
}
handlePopUpToggle("identityAuthMethod", false);
createNotification({
text: `Successfully ${isUpdate ? "updated" : "configured"} auth method`,
type: "success"
}); });
} else {
reset(); await addMutateAsync({
} catch { organizationId: orgId,
createNotification({ identityId,
text: `Failed to ${isUpdate ? "update" : "configure"} identity`, allowedArns,
type: "error" accessTokenTTL: Number(accessTokenTTL),
accessTokenMaxTTL: Number(accessTokenMaxTTL),
accessTokenNumUsesLimit: Number(accessTokenNumUsesLimit),
accessTokenTrustedIps
}); });
} }
handlePopUpToggle("identityAuthMethod", false);
createNotification({
text: `Successfully ${isUpdate ? "updated" : "configured"} auth method`,
type: "success"
});
reset();
}; };
return ( return (
@@ -103,56 +103,44 @@ export const IdentityAuthTemplateModal = ({ popUp, handlePopUpToggle }: Props) =
const selectedMethod = watch("method"); const selectedMethod = watch("method");
const onFormSubmit = async (data: FormData) => { const onFormSubmit = async (data: FormData) => {
try { if (isEdit && template) {
if (isEdit && template) { await updateTemplate({
await updateTemplate({ templateId: template.id,
templateId: template.id, organizationId: orgId,
organizationId: orgId, name: data.name,
name: data.name, templateFields: {
templateFields: { url: data.url,
url: data.url, bindDN: data.bindDN,
bindDN: data.bindDN, bindPass: data.bindPass,
bindPass: data.bindPass, searchBase: data.searchBase,
searchBase: data.searchBase, ldapCaCertificate: data.ldapCaCertificate
ldapCaCertificate: data.ldapCaCertificate }
} });
});
createNotification({
text: "Successfully updated auth template",
type: "success"
});
} else {
await createTemplate({
organizationId: orgId,
name: data.name,
authMethod: data.method,
templateFields: {
url: data.url,
bindDN: data.bindDN,
bindPass: data.bindPass,
searchBase: data.searchBase,
ldapCaCertificate: data.ldapCaCertificate
}
});
createNotification({
text: "Successfully created auth template",
type: "success"
});
}
handlePopUpToggle(isEdit ? "editTemplate" : "createTemplate", false);
reset();
} catch (err) {
console.error(err);
const error = err as any;
const text =
error?.response?.data?.message ?? `Failed to ${isEdit ? "update" : "create"} auth template`;
createNotification({ createNotification({
text, text: "Successfully updated auth template",
type: "error" type: "success"
});
} else {
await createTemplate({
organizationId: orgId,
name: data.name,
authMethod: data.method,
templateFields: {
url: data.url,
bindDN: data.bindDN,
bindPass: data.bindPass,
searchBase: data.searchBase,
ldapCaCertificate: data.ldapCaCertificate
}
});
createNotification({
text: "Successfully created auth template",
type: "success"
}); });
} }
handlePopUpToggle(isEdit ? "editTemplate" : "createTemplate", false);
reset();
}; };
const handleClose = () => { const handleClose = () => {
@@ -147,49 +147,42 @@ export const IdentityAwsAuthForm = ({
accessTokenNumUsesLimit, accessTokenNumUsesLimit,
accessTokenTrustedIps accessTokenTrustedIps
}: FormData) => { }: FormData) => {
try { if (!identityId) return;
if (!identityId) return;
if (data) { if (data) {
await updateMutateAsync({ await updateMutateAsync({
organizationId: orgId, organizationId: orgId,
stsEndpoint, stsEndpoint,
allowedPrincipalArns, allowedPrincipalArns,
allowedAccountIds, allowedAccountIds,
identityId, identityId,
accessTokenTTL: Number(accessTokenTTL), accessTokenTTL: Number(accessTokenTTL),
accessTokenMaxTTL: Number(accessTokenMaxTTL), accessTokenMaxTTL: Number(accessTokenMaxTTL),
accessTokenNumUsesLimit: Number(accessTokenNumUsesLimit), accessTokenNumUsesLimit: Number(accessTokenNumUsesLimit),
accessTokenTrustedIps accessTokenTrustedIps
});
} else {
await addMutateAsync({
organizationId: orgId,
identityId,
stsEndpoint: stsEndpoint || "",
allowedPrincipalArns: allowedPrincipalArns || "",
allowedAccountIds: allowedAccountIds || "",
accessTokenTTL: Number(accessTokenTTL),
accessTokenMaxTTL: Number(accessTokenMaxTTL),
accessTokenNumUsesLimit: Number(accessTokenNumUsesLimit),
accessTokenTrustedIps
});
}
handlePopUpToggle("identityAuthMethod", false);
createNotification({
text: `Successfully ${isUpdate ? "updated" : "configured"} auth method`,
type: "success"
}); });
} else {
reset(); await addMutateAsync({
} catch { organizationId: orgId,
createNotification({ identityId,
text: `Failed to ${isUpdate ? "update" : "configure"} identity`, stsEndpoint: stsEndpoint || "",
type: "error" allowedPrincipalArns: allowedPrincipalArns || "",
allowedAccountIds: allowedAccountIds || "",
accessTokenTTL: Number(accessTokenTTL),
accessTokenMaxTTL: Number(accessTokenMaxTTL),
accessTokenNumUsesLimit: Number(accessTokenNumUsesLimit),
accessTokenTrustedIps
}); });
} }
handlePopUpToggle("identityAuthMethod", false);
createNotification({
text: `Successfully ${isUpdate ? "updated" : "configured"} auth method`,
type: "success"
});
reset();
}; };
return ( return (
@@ -143,49 +143,42 @@ export const IdentityAzureAuthForm = ({
accessTokenNumUsesLimit, accessTokenNumUsesLimit,
accessTokenTrustedIps accessTokenTrustedIps
}: FormData) => { }: FormData) => {
try { if (!identityId) return;
if (!identityId) return;
if (data) { if (data) {
await updateMutateAsync({ await updateMutateAsync({
organizationId: orgId, organizationId: orgId,
identityId, identityId,
tenantId, tenantId,
resource, resource,
allowedServicePrincipalIds, allowedServicePrincipalIds,
accessTokenTTL: Number(accessTokenTTL), accessTokenTTL: Number(accessTokenTTL),
accessTokenMaxTTL: Number(accessTokenMaxTTL), accessTokenMaxTTL: Number(accessTokenMaxTTL),
accessTokenNumUsesLimit: Number(accessTokenNumUsesLimit), accessTokenNumUsesLimit: Number(accessTokenNumUsesLimit),
accessTokenTrustedIps accessTokenTrustedIps
});
} else {
await addMutateAsync({
organizationId: orgId,
identityId,
tenantId: tenantId || "",
resource: resource || "",
allowedServicePrincipalIds: allowedServicePrincipalIds || "",
accessTokenTTL: Number(accessTokenTTL),
accessTokenMaxTTL: Number(accessTokenMaxTTL),
accessTokenNumUsesLimit: Number(accessTokenNumUsesLimit),
accessTokenTrustedIps
});
}
handlePopUpToggle("identityAuthMethod", false);
createNotification({
text: `Successfully ${isUpdate ? "updated" : "configured"} auth method`,
type: "success"
}); });
} else {
reset(); await addMutateAsync({
} catch { organizationId: orgId,
createNotification({ identityId,
text: `Failed to ${isUpdate ? "update" : "configure"} identity`, tenantId: tenantId || "",
type: "error" resource: resource || "",
allowedServicePrincipalIds: allowedServicePrincipalIds || "",
accessTokenTTL: Number(accessTokenTTL),
accessTokenMaxTTL: Number(accessTokenMaxTTL),
accessTokenNumUsesLimit: Number(accessTokenNumUsesLimit),
accessTokenTrustedIps
}); });
} }
handlePopUpToggle("identityAuthMethod", false);
createNotification({
text: `Successfully ${isUpdate ? "updated" : "configured"} auth method`,
type: "success"
});
reset();
}; };
return ( return (
@@ -152,51 +152,44 @@ export const IdentityGcpAuthForm = ({
accessTokenNumUsesLimit, accessTokenNumUsesLimit,
accessTokenTrustedIps accessTokenTrustedIps
}: FormData) => { }: FormData) => {
try { if (!identityId) return;
if (!identityId) return;
if (data) { if (data) {
await updateMutateAsync({ await updateMutateAsync({
identityId, identityId,
organizationId: orgId, organizationId: orgId,
type, type,
allowedServiceAccounts, allowedServiceAccounts,
allowedProjects, allowedProjects,
allowedZones, allowedZones,
accessTokenTTL: Number(accessTokenTTL), accessTokenTTL: Number(accessTokenTTL),
accessTokenMaxTTL: Number(accessTokenMaxTTL), accessTokenMaxTTL: Number(accessTokenMaxTTL),
accessTokenNumUsesLimit: Number(accessTokenNumUsesLimit), accessTokenNumUsesLimit: Number(accessTokenNumUsesLimit),
accessTokenTrustedIps accessTokenTrustedIps
});
} else {
await addMutateAsync({
identityId,
organizationId: orgId,
type,
allowedServiceAccounts: allowedServiceAccounts || "",
allowedProjects: allowedProjects || "",
allowedZones: allowedZones || "",
accessTokenTTL: Number(accessTokenTTL),
accessTokenMaxTTL: Number(accessTokenMaxTTL),
accessTokenNumUsesLimit: Number(accessTokenNumUsesLimit),
accessTokenTrustedIps
});
}
handlePopUpToggle("identityAuthMethod", false);
createNotification({
text: `Successfully ${isUpdate ? "updated" : "configured"} auth method`,
type: "success"
}); });
} else {
reset(); await addMutateAsync({
} catch { identityId,
createNotification({ organizationId: orgId,
text: `Failed to ${isUpdate ? "update" : "configure"} identity`, type,
type: "error" allowedServiceAccounts: allowedServiceAccounts || "",
allowedProjects: allowedProjects || "",
allowedZones: allowedZones || "",
accessTokenTTL: Number(accessTokenTTL),
accessTokenMaxTTL: Number(accessTokenMaxTTL),
accessTokenNumUsesLimit: Number(accessTokenNumUsesLimit),
accessTokenTrustedIps
}); });
} }
handlePopUpToggle("identityAuthMethod", false);
createNotification({
text: `Successfully ${isUpdate ? "updated" : "configured"} auth method`,
type: "success"
});
reset();
}; };
return ( return (
@@ -217,61 +217,54 @@ export const IdentityJwtAuthForm = ({
boundClaims, boundClaims,
boundSubject boundSubject
}: FormData) => { }: FormData) => {
try { if (!identityId) {
if (!identityId) { return;
return; }
}
if (data) { if (data) {
await updateMutateAsync({ await updateMutateAsync({
identityId, identityId,
organizationId: orgId, organizationId: orgId,
configurationType, configurationType,
jwksUrl, jwksUrl,
jwksCaCert, jwksCaCert,
publicKeys: publicKeys?.map((field) => field.value).filter(Boolean), publicKeys: publicKeys?.map((field) => field.value).filter(Boolean),
boundIssuer, boundIssuer,
boundAudiences, boundAudiences,
boundClaims: Object.fromEntries(boundClaims.map((entry) => [entry.key, entry.value])), boundClaims: Object.fromEntries(boundClaims.map((entry) => [entry.key, entry.value])),
boundSubject, boundSubject,
accessTokenTTL: Number(accessTokenTTL), accessTokenTTL: Number(accessTokenTTL),
accessTokenMaxTTL: Number(accessTokenMaxTTL), accessTokenMaxTTL: Number(accessTokenMaxTTL),
accessTokenNumUsesLimit: Number(accessTokenNumUsesLimit), accessTokenNumUsesLimit: Number(accessTokenNumUsesLimit),
accessTokenTrustedIps accessTokenTrustedIps
});
} else {
await addMutateAsync({
identityId,
configurationType,
jwksUrl,
jwksCaCert,
publicKeys: publicKeys?.map((field) => field.value).filter(Boolean),
boundIssuer,
boundAudiences,
boundClaims: Object.fromEntries(boundClaims.map((entry) => [entry.key, entry.value])),
boundSubject,
organizationId: orgId,
accessTokenTTL: Number(accessTokenTTL),
accessTokenMaxTTL: Number(accessTokenMaxTTL),
accessTokenNumUsesLimit: Number(accessTokenNumUsesLimit),
accessTokenTrustedIps
});
}
handlePopUpToggle("identityAuthMethod", false);
createNotification({
text: `Successfully ${isUpdate ? "updated" : "configured"} auth method`,
type: "success"
}); });
} else {
reset(); await addMutateAsync({
} catch { identityId,
createNotification({ configurationType,
text: `Failed to ${isUpdate ? "update" : "configure"} identity`, jwksUrl,
type: "error" jwksCaCert,
publicKeys: publicKeys?.map((field) => field.value).filter(Boolean),
boundIssuer,
boundAudiences,
boundClaims: Object.fromEntries(boundClaims.map((entry) => [entry.key, entry.value])),
boundSubject,
organizationId: orgId,
accessTokenTTL: Number(accessTokenTTL),
accessTokenMaxTTL: Number(accessTokenMaxTTL),
accessTokenNumUsesLimit: Number(accessTokenNumUsesLimit),
accessTokenTrustedIps
}); });
} }
handlePopUpToggle("identityAuthMethod", false);
createNotification({
text: `Successfully ${isUpdate ? "updated" : "configured"} auth method`,
type: "success"
});
reset();
}; };
return ( return (
@@ -311,71 +311,64 @@ export const IdentityKubernetesAuthForm = ({
tokenReviewMode, tokenReviewMode,
accessTokenTrustedIps accessTokenTrustedIps
}: FormData) => { }: FormData) => {
try { if (!identityId) return;
if (!identityId) return;
if (data) { if (data) {
await updateMutateAsync({ await updateMutateAsync({
organizationId: orgId, organizationId: orgId,
...(tokenReviewMode === IdentityKubernetesAuthTokenReviewMode.Api ...(tokenReviewMode === IdentityKubernetesAuthTokenReviewMode.Api
? { ? {
kubernetesHost: kubernetesHost || "" kubernetesHost: kubernetesHost || ""
} }
: { : {
kubernetesHost: null kubernetesHost: null
}), }),
tokenReviewerJwt: tokenReviewerJwt || null, tokenReviewerJwt: tokenReviewerJwt || null,
allowedNames, allowedNames,
allowedNamespaces, allowedNamespaces,
allowedAudience, allowedAudience,
caCert, caCert,
identityId, identityId,
gatewayId: gatewayId || null, gatewayId: gatewayId || null,
tokenReviewMode, tokenReviewMode,
accessTokenTTL: Number(accessTokenTTL), accessTokenTTL: Number(accessTokenTTL),
accessTokenMaxTTL: Number(accessTokenMaxTTL), accessTokenMaxTTL: Number(accessTokenMaxTTL),
accessTokenNumUsesLimit: Number(accessTokenNumUsesLimit), accessTokenNumUsesLimit: Number(accessTokenNumUsesLimit),
accessTokenTrustedIps accessTokenTrustedIps
});
} else {
await addMutateAsync({
organizationId: orgId,
identityId,
...(tokenReviewMode === IdentityKubernetesAuthTokenReviewMode.Api
? {
kubernetesHost: kubernetesHost || ""
}
: {
kubernetesHost: null
}),
tokenReviewerJwt: tokenReviewerJwt || undefined,
allowedNames: allowedNames || "",
allowedNamespaces: allowedNamespaces || "",
allowedAudience: allowedAudience || "",
gatewayId: gatewayId || null,
caCert: caCert || "",
tokenReviewMode,
accessTokenTTL: Number(accessTokenTTL),
accessTokenMaxTTL: Number(accessTokenMaxTTL),
accessTokenNumUsesLimit: Number(accessTokenNumUsesLimit),
accessTokenTrustedIps
});
}
handlePopUpToggle("identityAuthMethod", false);
createNotification({
text: `Successfully ${isUpdate ? "updated" : "configured"} auth method`,
type: "success"
}); });
} else {
reset(); await addMutateAsync({
} catch { organizationId: orgId,
createNotification({ identityId,
text: `Failed to ${isUpdate ? "update" : "configure"} identity`, ...(tokenReviewMode === IdentityKubernetesAuthTokenReviewMode.Api
type: "error" ? {
kubernetesHost: kubernetesHost || ""
}
: {
kubernetesHost: null
}),
tokenReviewerJwt: tokenReviewerJwt || undefined,
allowedNames: allowedNames || "",
allowedNamespaces: allowedNamespaces || "",
allowedAudience: allowedAudience || "",
gatewayId: gatewayId || null,
caCert: caCert || "",
tokenReviewMode,
accessTokenTTL: Number(accessTokenTTL),
accessTokenMaxTTL: Number(accessTokenMaxTTL),
accessTokenNumUsesLimit: Number(accessTokenNumUsesLimit),
accessTokenTrustedIps
}); });
} }
handlePopUpToggle("identityAuthMethod", false);
createNotification({
text: `Successfully ${isUpdate ? "updated" : "configured"} auth method`,
type: "success"
});
reset();
}; };
const tokenReviewMode = watch("tokenReviewMode"); const tokenReviewMode = watch("tokenReviewMode");
@@ -316,83 +316,76 @@ export const IdentityLdapAuthForm = ({
}, [subscription, handlePopUpOpen, handlePopUpToggle]); }, [subscription, handlePopUpOpen, handlePopUpToggle]);
const onFormSubmit = async (formData: FormData) => { const onFormSubmit = async (formData: FormData) => {
try { if (!identityId) return;
if (!identityId) return;
const { const {
scope: submissionScope, scope: submissionScope,
templateId: submissionTemplateId, templateId: submissionTemplateId,
url: submissionUrl, url: submissionUrl,
bindDN: submissionBindDN, bindDN: submissionBindDN,
bindPass: submissionBindPass, bindPass: submissionBindPass,
searchBase: submissionSearchBase, searchBase: submissionSearchBase,
searchFilter, searchFilter,
ldapCaCertificate, ldapCaCertificate,
allowedFields, allowedFields,
accessTokenTTL, accessTokenTTL,
accessTokenMaxTTL, accessTokenMaxTTL,
accessTokenNumUsesLimit, accessTokenNumUsesLimit,
accessTokenTrustedIps, accessTokenTrustedIps,
lockoutEnabled, lockoutEnabled,
lockoutThreshold, lockoutThreshold,
lockoutDurationValue, lockoutDurationValue,
lockoutDurationUnit, lockoutDurationUnit,
lockoutCounterResetValue, lockoutCounterResetValue,
lockoutCounterResetUnit lockoutCounterResetUnit
} = formData; } = formData;
const lockoutDurationSeconds = ms(`${lockoutDurationValue}${lockoutDurationUnit}`) / 1000; const lockoutDurationSeconds = ms(`${lockoutDurationValue}${lockoutDurationUnit}`) / 1000;
const lockoutCounterResetSeconds = const lockoutCounterResetSeconds =
ms(`${lockoutCounterResetValue}${lockoutCounterResetUnit}`) / 1000; ms(`${lockoutCounterResetValue}${lockoutCounterResetUnit}`) / 1000;
const basePayload = { const basePayload = {
organizationId: orgId, organizationId: orgId,
identityId, identityId,
searchFilter, searchFilter,
ldapCaCertificate, ldapCaCertificate,
allowedFields, allowedFields,
accessTokenTTL: Number(accessTokenTTL), accessTokenTTL: Number(accessTokenTTL),
accessTokenMaxTTL: Number(accessTokenMaxTTL), accessTokenMaxTTL: Number(accessTokenMaxTTL),
accessTokenNumUsesLimit: Number(accessTokenNumUsesLimit), accessTokenNumUsesLimit: Number(accessTokenNumUsesLimit),
accessTokenTrustedIps, accessTokenTrustedIps,
lockoutEnabled, lockoutEnabled,
lockoutThreshold: Number(lockoutThreshold), lockoutThreshold: Number(lockoutThreshold),
lockoutDurationSeconds, lockoutDurationSeconds,
lockoutCounterResetSeconds lockoutCounterResetSeconds
}; };
// Add scope-specific fields // Add scope-specific fields
const payload = const payload =
submissionScope === "template" submissionScope === "template"
? { ...basePayload, templateId: submissionTemplateId } ? { ...basePayload, templateId: submissionTemplateId }
: { : {
...basePayload, ...basePayload,
url: submissionUrl, url: submissionUrl,
bindDN: submissionBindDN, bindDN: submissionBindDN,
bindPass: submissionBindPass, bindPass: submissionBindPass,
searchBase: submissionSearchBase searchBase: submissionSearchBase
}; };
if (data) { if (data) {
await updateMutateAsync(payload); await updateMutateAsync(payload);
} else { } else {
await addMutateAsync(payload); await addMutateAsync(payload);
}
handlePopUpToggle("identityAuthMethod", false);
createNotification({
text: `Successfully ${isUpdate ? "updated" : "configured"} auth method`,
type: "success"
});
reset();
} catch {
createNotification({
text: `Failed to ${isUpdate ? "update" : "configure"} identity`,
type: "error"
});
} }
handlePopUpToggle("identityAuthMethod", false);
createNotification({
text: `Successfully ${isUpdate ? "updated" : "configured"} auth method`,
type: "success"
});
reset();
}; };
return ( return (
@@ -42,31 +42,20 @@ export const IdentityLinkForm = ({ onClose }: Props) => {
}); });
const onFormSubmit = async ({ identity, role }: FormData) => { const onFormSubmit = async ({ identity, role }: FormData) => {
try { await createMutateAsync({
await createMutateAsync({ identityId: identity.id,
identityId: identity.id, roles: [{ role: role.slug, isTemporary: false }]
roles: [{ role: role.slug, isTemporary: false }] });
}); createNotification({
createNotification({ text: "Successfully linked identity",
text: "Successfully linked identity", type: "success"
type: "success" });
}); navigate({
navigate({ to: "/organization/identities/$identityId",
to: "/organization/identities/$identityId", params: {
params: { identityId: identity.id
identityId: identity.id }
} });
});
} catch (err) {
console.error(err);
const error = err as any;
const text = error?.response?.data?.message ?? "Failed to link identity";
createNotification({
text,
type: "error"
});
}
}; };
return ( return (
@@ -108,81 +108,68 @@ export const IdentityModal = ({ popUp, handlePopUpToggle }: Props) => {
}, [popUp?.identity?.data, roles]); }, [popUp?.identity?.data, roles]);
const onFormSubmit = async ({ name, role, metadata, hasDeleteProtection }: FormData) => { const onFormSubmit = async ({ name, role, metadata, hasDeleteProtection }: FormData) => {
try { const identity = popUp?.identity?.data as {
const identity = popUp?.identity?.data as { identityId: string;
identityId: string; name: string;
name: string; role: string;
role: string; hasDeleteProtection: boolean;
hasDeleteProtection: boolean; orgId: string;
orgId: string; };
};
if (identity) { if (identity) {
// update // update
await updateMutateAsync({ await updateMutateAsync({
identityId: identity.identityId, identityId: identity.identityId,
name, name,
role: role.slug || undefined, role: role.slug || undefined,
hasDeleteProtection, hasDeleteProtection,
organizationId: orgId, organizationId: orgId,
metadata metadata
});
handlePopUpToggle("identity", false);
} else {
// create
const { id: createdId } = await createMutateAsync({
name,
role: role.slug || undefined,
hasDeleteProtection,
organizationId: orgId,
metadata
});
await addMutateAsync({
organizationId: orgId,
identityId: createdId,
clientSecretTrustedIps: [{ ipAddress: "0.0.0.0/0" }, { ipAddress: "::/0" }],
accessTokenTrustedIps: [{ ipAddress: "0.0.0.0/0" }, { ipAddress: "::/0" }],
accessTokenTTL: 2592000,
accessTokenMaxTTL: 2592000,
accessTokenNumUsesLimit: 0,
accessTokenPeriod: 0,
lockoutEnabled: true,
lockoutThreshold: 3,
lockoutDurationSeconds: 300,
lockoutCounterResetSeconds: 30
});
handlePopUpToggle("identity", false);
navigate({
to: "/organization/identities/$identityId",
params: {
identityId: createdId
}
});
}
createNotification({
text: `Successfully ${popUp?.identity?.data ? "updated" : "created"} identity`,
type: "success"
}); });
reset(); handlePopUpToggle("identity", false);
} catch (err) { } else {
console.error(err); // create
const error = err as any;
const text =
error?.response?.data?.message ??
`Failed to ${popUp?.identity?.data ? "update" : "create"} identity`;
createNotification({ const { id: createdId } = await createMutateAsync({
text, name,
type: "error" role: role.slug || undefined,
hasDeleteProtection,
organizationId: orgId,
metadata
});
await addMutateAsync({
organizationId: orgId,
identityId: createdId,
clientSecretTrustedIps: [{ ipAddress: "0.0.0.0/0" }, { ipAddress: "::/0" }],
accessTokenTrustedIps: [{ ipAddress: "0.0.0.0/0" }, { ipAddress: "::/0" }],
accessTokenTTL: 2592000,
accessTokenMaxTTL: 2592000,
accessTokenNumUsesLimit: 0,
accessTokenPeriod: 0,
lockoutEnabled: true,
lockoutThreshold: 3,
lockoutDurationSeconds: 300,
lockoutCounterResetSeconds: 30
});
handlePopUpToggle("identity", false);
navigate({
to: "/organization/identities/$identityId",
params: {
identityId: createdId
}
}); });
} }
createNotification({
text: `Successfully ${popUp?.identity?.data ? "updated" : "created"} identity`,
type: "success"
});
reset();
}; };
return ( return (
@@ -149,47 +149,40 @@ export const IdentityOciAuthForm = ({
accessTokenNumUsesLimit, accessTokenNumUsesLimit,
accessTokenTrustedIps accessTokenTrustedIps
}: FormData) => { }: FormData) => {
try { if (!identityId) return;
if (!identityId) return;
if (data) { if (data) {
await updateMutateAsync({ await updateMutateAsync({
organizationId: orgId, organizationId: orgId,
tenancyOcid, tenancyOcid,
allowedUsernames, allowedUsernames,
identityId, identityId,
accessTokenTTL: Number(accessTokenTTL), accessTokenTTL: Number(accessTokenTTL),
accessTokenMaxTTL: Number(accessTokenMaxTTL), accessTokenMaxTTL: Number(accessTokenMaxTTL),
accessTokenNumUsesLimit: Number(accessTokenNumUsesLimit), accessTokenNumUsesLimit: Number(accessTokenNumUsesLimit),
accessTokenTrustedIps accessTokenTrustedIps
});
} else {
await addMutateAsync({
organizationId: orgId,
identityId,
tenancyOcid,
allowedUsernames: allowedUsernames || undefined,
accessTokenTTL: Number(accessTokenTTL),
accessTokenMaxTTL: Number(accessTokenMaxTTL),
accessTokenNumUsesLimit: Number(accessTokenNumUsesLimit),
accessTokenTrustedIps
});
}
handlePopUpToggle("identityAuthMethod", false);
createNotification({
text: `Successfully ${isUpdate ? "updated" : "configured"} auth method`,
type: "success"
}); });
} else {
reset(); await addMutateAsync({
} catch { organizationId: orgId,
createNotification({ identityId,
text: `Failed to ${isUpdate ? "update" : "configure"} identity`, tenancyOcid,
type: "error" allowedUsernames: allowedUsernames || undefined,
accessTokenTTL: Number(accessTokenTTL),
accessTokenMaxTTL: Number(accessTokenMaxTTL),
accessTokenNumUsesLimit: Number(accessTokenNumUsesLimit),
accessTokenTrustedIps
}); });
} }
handlePopUpToggle("identityAuthMethod", false);
createNotification({
text: `Successfully ${isUpdate ? "updated" : "configured"} auth method`,
type: "success"
});
reset();
}; };
return ( return (
@@ -201,63 +201,56 @@ export const IdentityOidcAuthForm = ({
claimMetadataMapping, claimMetadataMapping,
boundSubject boundSubject
}: FormData) => { }: FormData) => {
try { if (!identityId) {
if (!identityId) { return;
return; }
}
if (data) { if (data) {
await updateMutateAsync({ await updateMutateAsync({
identityId, identityId,
organizationId: orgId, organizationId: orgId,
oidcDiscoveryUrl, oidcDiscoveryUrl,
caCert, caCert,
boundIssuer, boundIssuer,
boundAudiences, boundAudiences,
boundClaims: Object.fromEntries(boundClaims.map((entry) => [entry.key, entry.value])), boundClaims: Object.fromEntries(boundClaims.map((entry) => [entry.key, entry.value])),
claimMetadataMapping: claimMetadataMapping claimMetadataMapping: claimMetadataMapping
? Object.fromEntries(claimMetadataMapping.map((entry) => [entry.key, entry.value])) ? Object.fromEntries(claimMetadataMapping.map((entry) => [entry.key, entry.value]))
: undefined, : undefined,
boundSubject, boundSubject,
accessTokenTTL: Number(accessTokenTTL), accessTokenTTL: Number(accessTokenTTL),
accessTokenMaxTTL: Number(accessTokenMaxTTL), accessTokenMaxTTL: Number(accessTokenMaxTTL),
accessTokenNumUsesLimit: Number(accessTokenNumUsesLimit), accessTokenNumUsesLimit: Number(accessTokenNumUsesLimit),
accessTokenTrustedIps accessTokenTrustedIps
});
} else {
await addMutateAsync({
identityId,
oidcDiscoveryUrl,
caCert,
boundIssuer,
boundAudiences,
boundClaims: Object.fromEntries(boundClaims.map((entry) => [entry.key, entry.value])),
claimMetadataMapping: claimMetadataMapping
? Object.fromEntries(claimMetadataMapping.map((entry) => [entry.key, entry.value]))
: undefined,
boundSubject,
organizationId: orgId,
accessTokenTTL: Number(accessTokenTTL),
accessTokenMaxTTL: Number(accessTokenMaxTTL),
accessTokenNumUsesLimit: Number(accessTokenNumUsesLimit),
accessTokenTrustedIps
});
}
handlePopUpToggle("identityAuthMethod", false);
createNotification({
text: `Successfully ${isUpdate ? "updated" : "configured"} auth method`,
type: "success"
}); });
} else {
reset(); await addMutateAsync({
} catch { identityId,
createNotification({ oidcDiscoveryUrl,
text: `Failed to ${isUpdate ? "update" : "configure"} identity`, caCert,
type: "error" boundIssuer,
boundAudiences,
boundClaims: Object.fromEntries(boundClaims.map((entry) => [entry.key, entry.value])),
claimMetadataMapping: claimMetadataMapping
? Object.fromEntries(claimMetadataMapping.map((entry) => [entry.key, entry.value]))
: undefined,
boundSubject,
organizationId: orgId,
accessTokenTTL: Number(accessTokenTTL),
accessTokenMaxTTL: Number(accessTokenMaxTTL),
accessTokenNumUsesLimit: Number(accessTokenNumUsesLimit),
accessTokenTrustedIps
}); });
} }
handlePopUpToggle("identityAuthMethod", false);
createNotification({
text: `Successfully ${isUpdate ? "updated" : "configured"} auth method`,
type: "success"
});
reset();
}; };
return ( return (