From e8c0d1ece90f78b5832faf136587d54fcbda3c62 Mon Sep 17 00:00:00 2001 From: = Date: Fri, 13 Sep 2024 02:00:58 +0530 Subject: [PATCH] fix: resolved entra failing --- backend/src/ee/routes/v1/saml-router.ts | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/backend/src/ee/routes/v1/saml-router.ts b/backend/src/ee/routes/v1/saml-router.ts index 716c23fe5..a5b0960b0 100644 --- a/backend/src/ee/routes/v1/saml-router.ts +++ b/backend/src/ee/routes/v1/saml-router.ts @@ -100,9 +100,20 @@ export const registerSamlRouter = async (server: FastifyZodProvider) => { async (req, profile, cb) => { try { if (!profile) throw new BadRequestError({ message: "Missing profile" }); - const email = profile?.email ?? (profile?.emailAddress as string); // emailRippling is added because in Rippling the field `email` reserved + const email = + profile?.email ?? + // entra sends data in this format + (profile["http://schemas.xmlsoap.org/ws/2005/05/identity/claims/email"] as string) ?? + (profile?.emailAddress as string); // emailRippling is added because in Rippling the field `email` reserved\ - if (!email || !profile.firstName) { + const firstName = (profile.firstName ?? + // entra sends data in this format + profile["http://schemas.xmlsoap.org/ws/2005/05/identity/claims/firstName"]) as string; + + const lastName = + profile.lastName ?? profile["http://schemas.xmlsoap.org/ws/2005/05/identity/claims/lastName"]; + + if (!email || !firstName) { logger.info( { err: new Error("Invalid saml request. Missing email or first name"), @@ -110,14 +121,13 @@ export const registerSamlRouter = async (server: FastifyZodProvider) => { }, `email: ${email} firstName: ${profile.firstName as string}` ); - throw new BadRequestError({ message: "Invalid request. Missing email or first name" }); } const { isUserCompleted, providerAuthToken } = await server.services.saml.samlLogin({ externalId: profile.nameID, email, - firstName: profile.firstName as string, - lastName: profile.lastName as string, + firstName, + lastName: lastName as string, relayState: (req.body as { RelayState?: string }).RelayState, authProvider: (req as unknown as FastifyRequest).ssoConfig?.authProvider as string, orgId: (req as unknown as FastifyRequest).ssoConfig?.orgId as string