Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.
TypeScript acmeagentsai-agentscertificate-managementdevsecopsenvironment-variableskubernetesopen-sourcepampkipostgresprivate-caprivileged-access-managementsecret-managementsecret-managersecretssecrets-managementsecuritysecurity-toolsvault
Add orgId to reuse login1/login2 logic for LDAP 2nd step login
Tuan Dang9ba4b939a402
diff --git a/backend/src/ee/services/ldap-config/ldap-config-service.ts b/backend/src/ee/services/ldap-config/ldap-config-service.tsindex 45d75bd777..c452b6a3a3 100644--- a/backend/src/ee/services/ldap-config/ldap-config-service.ts+++ b/backend/src/ee/services/ldap-config/ldap-config-service.ts@@ -370,16 +370,21 @@ export const ldapConfigServiceFactory = ({orgId,firstName,lastName,- authMethods: [AuthMethod.EMAIL],+ authMethods: [AuthMethod.LDAP],isGhost: false},tx);- await orgDAL.createMembership({- orgId,- role: OrgMembershipRole.Member,- status: OrgMembershipStatus.Invited- });+ await orgDAL.createMembership(+ {+ userId: newUser.id,+ orgId,+ role: OrgMembershipRole.Member,+ status: OrgMembershipStatus.Invited+ },+ tx+ );+return newUser;});}diff --git a/backend/src/server/routes/v3/login-router.ts b/backend/src/server/routes/v3/login-router.tsindex 240aa21b1e..0c3f8b2238 100644--- a/backend/src/server/routes/v3/login-router.ts+++ b/backend/src/server/routes/v3/login-router.ts@@ -13,6 +13,7 @@ export const registerLoginRouter = async (server: FastifyZodProvider) => {schema: {body: z.object({email: z.string().trim(),+ orgId: z.string().optional(),providerAuthToken: z.string().trim().optional(),clientPublicKey: z.string().trim()}),@@ -26,6 +27,7 @@ export const registerLoginRouter = async (server: FastifyZodProvider) => {handler: async (req) => {const { serverPublicKey, salt } = await server.services.login.loginGenServerPublicKey({email: req.body.email,+ userOrgId: req.body.orgId,clientPublicKey: req.body.clientPublicKey,providerAuthToken: req.body.providerAuthToken});@@ -43,6 +45,7 @@ export const registerLoginRouter = async (server: FastifyZodProvider) => {schema: {body: z.object({email: z.string().trim(),+ orgId: z.string().optional(),providerAuthToken: z.string().trim().optional(),clientProof: z.string().trim()}),@@ -71,6 +74,7 @@ export const registerLoginRouter = async (server: FastifyZodProvider) => {const data = await server.services.login.loginExchangeClientProof({email: req.body.email,+ userOrgId: req.body.orgId,ip: req.realIp,userAgent,providerAuthToken: req.body.providerAuthToken,diff --git a/backend/src/services/auth/auth-login-service.ts b/backend/src/services/auth/auth-login-service.tsindex cd44c75245..ab490bdb43 100644--- a/backend/src/services/auth/auth-login-service.ts+++ b/backend/src/services/auth/auth-login-service.ts@@ -130,10 +130,14 @@ export const authLoginServiceFactory = ({ userDAL, tokenService, smtpService }:*/const loginGenServerPublicKey = async ({email,+ userOrgId,providerAuthToken,clientPublicKey}: TLoginGenServerPublicKeyDTO) => {- const userEnc = await userDAL.findUserEncKeyByUsername(email);+ const userEnc = await userDAL.findUserEncKeyByUsername({+ username: email,+ orgId: userOrgId+ });if (!userEnc || (userEnc && !userEnc.isAccepted)) {throw new Error("Failed to find user");}@@ -155,12 +159,16 @@ export const authLoginServiceFactory = ({ userDAL, tokenService, smtpService }:*/const loginExchangeClientProof = async ({email,+ userOrgId,clientProof,providerAuthToken,ip,userAgent}: TLoginClientProofDTO) => {- const userEnc = await userDAL.findUserEncKeyByUsername(email);+ const userEnc = await userDAL.findUserEncKeyByUsername({+ username: email,+ orgId: userOrgId+ });if (!userEnc) throw new Error("Failed to find user");const cfg = getConfig();diff --git a/backend/src/services/auth/auth-login-type.ts b/backend/src/services/auth/auth-login-type.tsindex 86af5a5f9e..42a7dd968f 100644--- a/backend/src/services/auth/auth-login-type.ts+++ b/backend/src/services/auth/auth-login-type.ts@@ -2,12 +2,14 @@ import { AuthMethod } from "./auth-type";export type TLoginGenServerPublicKeyDTO = {email: string;+ userOrgId?: string;clientPublicKey: string;providerAuthToken?: string;};export type TLoginClientProofDTO = {email: string;+ userOrgId?: string;clientProof: string;providerAuthToken?: string;ip: string;diff --git a/backend/src/services/user/user-dal.ts b/backend/src/services/user/user-dal.tsindex c5a7669860..7488da560e 100644--- a/backend/src/services/user/user-dal.ts+++ b/backend/src/services/user/user-dal.ts@@ -20,10 +20,14 @@ export const userDALFactory = (db: TDbClient) => {// USER ENCRYPTION FUNCTIONS// -------------------------- const findUserEncKeyByUsername = async (username: string) => {+ const findUserEncKeyByUsername = async ({ username, orgId }: { username: string; orgId?: string }) => {try {return await db(TableName.Users)- .where({ username, isGhost: false })+ .where({+ username,+ ...(orgId ? { orgId } : { orgId: null }),+ isGhost: false+ }).join(TableName.UserEncryptionKey, `${TableName.Users}.id`, `${TableName.UserEncryptionKey}.userId`).first();} catch (error) {diff --git a/frontend/src/components/utilities/attemptLogin.ts b/frontend/src/components/utilities/attemptLogin.tsindex 195cf9b9a2..4942a6ae6c 100644--- a/frontend/src/components/utilities/attemptLogin.ts+++ b/frontend/src/components/utilities/attemptLogin.ts@@ -21,10 +21,12 @@ interface IsLoginSuccessful {*/const attemptLogin = async ({email,+ orgId,password,providerAuthToken}: {email: string;+ orgId?: string;password: string;providerAuthToken?: string;}): Promise<IsLoginSuccessful> => {@@ -38,6 +40,7 @@ const attemptLogin = async ({const { serverPublicKey, salt } = await login1({email,+ orgId,clientPublicKey,providerAuthToken});@@ -59,6 +62,7 @@ const attemptLogin = async ({tag} = await login2({email,+ orgId,clientProof,providerAuthToken});diff --git a/frontend/src/hooks/api/auth/types.ts b/frontend/src/hooks/api/auth/types.tsindex a18d023c46..c4e4e6fcea 100644--- a/frontend/src/hooks/api/auth/types.ts+++ b/frontend/src/hooks/api/auth/types.ts@@ -25,12 +25,14 @@ export type VerifyMfaTokenRes = {export type Login1DTO = {email: string;+ orgId?: string;clientPublicKey: string;providerAuthToken?: string;}export type Login2DTO = {email: string;+ orgId?: string;clientProof: string;providerAuthToken?: string;}diff --git a/frontend/src/views/Login/components/PasswordStep/PasswordStep.tsx b/frontend/src/views/Login/components/PasswordStep/PasswordStep.tsxindex 6924da3e75..50355362ce 100644--- a/frontend/src/views/Login/components/PasswordStep/PasswordStep.tsx+++ b/frontend/src/views/Login/components/PasswordStep/PasswordStep.tsx@@ -78,6 +78,7 @@ export const PasswordStep = ({} else {const loginAttempt = await attemptLogin({email,+ orgId: organizationId,password,providerAuthToken,});