mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-07 07:27:58 +00:00
misc: added frontend validation for oidc form
This commit is contained in:
@@ -29,18 +29,67 @@ type Props = {
|
|||||||
handlePopUpToggle: (popUpName: keyof UsePopUpState<["addOIDC"]>, state?: boolean) => void;
|
handlePopUpToggle: (popUpName: keyof UsePopUpState<["addOIDC"]>, state?: boolean) => void;
|
||||||
};
|
};
|
||||||
|
|
||||||
const schema = z.object({
|
const schema = z
|
||||||
configurationType: z.string(),
|
.object({
|
||||||
issuer: z.string().optional(),
|
configurationType: z.string(),
|
||||||
discoveryURL: z.string().optional(),
|
issuer: z.string().optional(),
|
||||||
authorizationEndpoint: z.string().optional(),
|
discoveryURL: z.string().optional(),
|
||||||
jwksUri: z.string().optional(),
|
authorizationEndpoint: z.string().optional(),
|
||||||
tokenEndpoint: z.string().optional(),
|
jwksUri: z.string().optional(),
|
||||||
userinfoEndpoint: z.string().optional(),
|
tokenEndpoint: z.string().optional(),
|
||||||
clientId: z.string().min(1),
|
userinfoEndpoint: z.string().optional(),
|
||||||
clientSecret: z.string().min(1),
|
clientId: z.string().min(1),
|
||||||
allowedEmailDomains: z.string().optional()
|
clientSecret: z.string().min(1),
|
||||||
});
|
allowedEmailDomains: z.string().optional()
|
||||||
|
})
|
||||||
|
.superRefine((data, ctx) => {
|
||||||
|
if (data.configurationType === ConfigurationType.CUSTOM) {
|
||||||
|
if (!data.issuer) {
|
||||||
|
ctx.addIssue({
|
||||||
|
path: ["issuer"],
|
||||||
|
message: "Issuer is required",
|
||||||
|
code: z.ZodIssueCode.custom
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if (!data.authorizationEndpoint) {
|
||||||
|
ctx.addIssue({
|
||||||
|
path: ["authorizationEndpoint"],
|
||||||
|
message: "Authorization endpoint is required",
|
||||||
|
code: z.ZodIssueCode.custom
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if (!data.jwksUri) {
|
||||||
|
ctx.addIssue({
|
||||||
|
path: ["jwksUri"],
|
||||||
|
message: "JWKS URI is required",
|
||||||
|
code: z.ZodIssueCode.custom
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if (!data.tokenEndpoint) {
|
||||||
|
ctx.addIssue({
|
||||||
|
path: ["tokenEndpoint"],
|
||||||
|
message: "Token endpoint is required",
|
||||||
|
code: z.ZodIssueCode.custom
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if (!data.userinfoEndpoint) {
|
||||||
|
ctx.addIssue({
|
||||||
|
path: ["userinfoEndpoint"],
|
||||||
|
message: "Userinfo endpoint is required",
|
||||||
|
code: z.ZodIssueCode.custom
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// eslint-disable-next-line no-lonely-if
|
||||||
|
if (!data.discoveryURL) {
|
||||||
|
ctx.addIssue({
|
||||||
|
path: ["discoveryURL"],
|
||||||
|
message: "Discovery URL is required",
|
||||||
|
code: z.ZodIssueCode.custom
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
export type OIDCFormData = z.infer<typeof schema>;
|
export type OIDCFormData = z.infer<typeof schema>;
|
||||||
|
|
||||||
@@ -88,7 +137,9 @@ export const OIDCModal = ({ popUp, handlePopUpClose, handlePopUpToggle }: Props)
|
|||||||
clientSecret
|
clientSecret
|
||||||
}: OIDCFormData) => {
|
}: OIDCFormData) => {
|
||||||
try {
|
try {
|
||||||
if (!currentOrg) return;
|
if (!currentOrg) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (!data) {
|
if (!data) {
|
||||||
await createMutateAsync({
|
await createMutateAsync({
|
||||||
|
|||||||
Reference in New Issue
Block a user