Skip to content

Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.

feat: improved saml error messages

=f5d7809515a0
diff --git a/backend/src/@types/fastify.d.ts b/backend/src/@types/fastify.d.ts
index e3261db700..441d3ce4cd 100644
--- a/backend/src/@types/fastify.d.ts
+++ b/backend/src/@types/fastify.d.ts
@@ -136,7 +136,7 @@ declare module "fastify" {
rateLimits: RateLimitConfiguration;
// passport data
passportUser: {
- isUserCompleted: string;
+ isUserCompleted: boolean;
providerAuthToken: string;
};
kmipUser: {
diff --git a/backend/src/ee/routes/v1/saml-router.ts b/backend/src/ee/routes/v1/saml-router.ts
index 13ac5dfcbc..f2df2fb896 100644
--- a/backend/src/ee/routes/v1/saml-router.ts
+++ b/backend/src/ee/routes/v1/saml-router.ts
@@ -223,12 +223,18 @@ export const registerSamlRouter = async (server: FastifyZodProvider) => {
samlConfigId: z.string().trim()
})
},
- preValidation: passport.authenticate("saml", {
- session: false,
- failureFlash: true,
- failureRedirect: "/login/provider/error"
- // this is due to zod type difference
- }) as any,
+ preValidation: passport.authenticate(
+ "saml",
+ {
+ session: false
+ },
+ async (req, res, err, user) => {
+ if (err) {
+ throw new BadRequestError({ message: `Saml authentication failed. ${err?.message}`, error: err });
+ }
+ req.passportUser = user as { isUserCompleted: boolean; providerAuthToken: string };
+ }
+ ) as any, // this is due to zod type difference
handler: (req, res) => {
if (req.passportUser.isUserCompleted) {
return res.redirect(