Skip to content

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

feat(infisical-pg): fixed some bugs on org invite missing auth method

Akhil Mohandeb8e7474958
diff --git a/backend-pg/src/server/routes/index.ts b/backend-pg/src/server/routes/index.ts
index 7544a67c43..a862f5b624 100644
--- a/backend-pg/src/server/routes/index.ts
+++ b/backend-pg/src/server/routes/index.ts
@@ -245,7 +245,8 @@ export const registerRoutes = async (
const superAdminService = superAdminServiceFactory({
userDal,
authService: loginService,
- serverCfgDal: superAdminDal
+ serverCfgDal: superAdminDal,
+ orgService
});
const apiKeyService = apiKeyServiceFactory({ apiKeyDal, userDal });
diff --git a/backend-pg/src/server/routes/v1/password-router.ts b/backend-pg/src/server/routes/v1/password-router.ts
index f8f30a0554..c9643ebdfe 100644
--- a/backend-pg/src/server/routes/v1/password-router.ts
+++ b/backend-pg/src/server/routes/v1/password-router.ts
@@ -118,4 +118,35 @@ export const registerPasswordRouter = async (server: FastifyZodProvider) => {
return { message: "Successfully updated backup private key", backupPrivateKey };
}
});
+
+ server.route({
+ method: "POST",
+ url: "/password-reset",
+ onRequest: verifyAuth([AuthMode.JWT]),
+ schema: {
+ body: z.object({
+ protectedKey: z.string().trim(),
+ protectedKeyIV: z.string().trim(),
+ protectedKeyTag: z.string().trim(),
+ encryptedPrivateKey: z.string().trim(),
+ encryptedPrivateKeyIV: z.string().trim(),
+ encryptedPrivateKeyTag: z.string().trim(),
+ salt: z.string().trim(),
+ verifier: z.string().trim()
+ }),
+ response: {
+ 200: z.object({
+ message: z.string()
+ })
+ }
+ },
+ handler: async (req) => {
+ await server.services.password.resetPasswordByBackupKey({
+ ...req.body,
+ userId: req.permission.id
+ });
+
+ return { message: "Successfully updated backup private key" };
+ }
+ });
};
diff --git a/backend-pg/src/services/auth/auth-password-service.ts b/backend-pg/src/services/auth/auth-password-service.ts
index d44b6c602e..75319ecfe9 100644
--- a/backend-pg/src/services/auth/auth-password-service.ts
+++ b/backend-pg/src/services/auth/auth-password-service.ts
@@ -157,19 +157,17 @@ export const authPaswordServiceFactory = ({
/*
* Reset password of a user via backup key
* */
- const resetPasswordByBackupKey = async (
- userId: string,
- {
- encryptedPrivateKey,
- protectedKeyTag,
- protectedKey,
- protectedKeyIV,
- salt,
- verifier,
- encryptedPrivateKeyIV,
- encryptedPrivateKeyTag
- }: TResetPasswordViaBackupKeyDTO
- ) => {
+ const resetPasswordByBackupKey = async ({
+ encryptedPrivateKey,
+ protectedKeyTag,
+ protectedKey,
+ protectedKeyIV,
+ salt,
+ verifier,
+ encryptedPrivateKeyIV,
+ encryptedPrivateKeyTag,
+ userId
+ }: TResetPasswordViaBackupKeyDTO) => {
await userDal.updateUserEncryptionByUserId(userId, {
encryptionVersion: 2,
protectedKey,
diff --git a/backend-pg/src/services/org/org-service.ts b/backend-pg/src/services/org/org-service.ts
index d0a72fc51e..f6600ebc05 100644
--- a/backend-pg/src/services/org/org-service.ts
+++ b/backend-pg/src/services/org/org-service.ts
@@ -15,7 +15,7 @@ import { generateSymmetricKey, infisicalSymmetricEncypt } from "@app/lib/crypto/
import { BadRequestError, UnauthorizedError } from "@app/lib/errors";
import { isDisposableEmail } from "@app/lib/validator";
-import { AuthTokenType } from "../auth/auth-type";
+import { AuthMethod, AuthTokenType } from "../auth/auth-type";
import { TAuthTokenServiceFactory } from "../auth-token/auth-token-service";
import { TokenType } from "../auth-token/auth-token-types";
import { SmtpTemplates, TSmtpService } from "../smtp/smtp-service";
@@ -284,14 +284,24 @@ export const orgServiceFactory = ({
});
}
// not invited before
- const user = await userDal.create({ email: inviteeEmail, isAccepted: false });
- await orgDal.createMembership({
- inviteEmail: inviteeEmail,
- orgId,
- userId: user.id,
- role: OrgMembershipRole.Member,
- status: OrgMembershipStatus.Invited
- });
+ const user = await userDal.create(
+ {
+ email: inviteeEmail,
+ isAccepted: false,
+ authMethods: [AuthMethod.EMAIL]
+ },
+ tx
+ );
+ await orgDal.createMembership(
+ {
+ inviteEmail: inviteeEmail,
+ orgId,
+ userId: user.id,
+ role: OrgMembershipRole.Member,
+ status: OrgMembershipStatus.Invited
+ },
+ tx
+ );
return user;
});
diff --git a/backend-pg/src/services/super-admin/super-admin-service.ts b/backend-pg/src/services/super-admin/super-admin-service.ts
index 325008a4ff..32b9ba8704 100644
--- a/backend-pg/src/services/super-admin/super-admin-service.ts
+++ b/backend-pg/src/services/super-admin/super-admin-service.ts
@@ -5,11 +5,14 @@ import { TAuthLoginFactory } from "../auth/auth-login-service";
import { TUserDalFactory } from "../user/user-dal";
import { TSuperAdminDalFactory } from "./super-admin-dal";
import { TAdminSignUpDTO } from "./super-admin-types";
+import { TOrgServiceFactory } from "../org/org-service";
+import { AuthMethod } from "../auth/auth-type";
type TSuperAdminServiceFactoryDep = {
serverCfgDal: TSuperAdminDalFactory;
userDal: TUserDalFactory;
authService: Pick<TAuthLoginFactory, "generateUserTokens">;
+ orgService: Pick<TOrgServiceFactory, "createOrganization">;
};
export type TSuperAdminServiceFactory = ReturnType<typeof superAdminServiceFactory>;
@@ -17,7 +20,8 @@ export type TSuperAdminServiceFactory = ReturnType<typeof superAdminServiceFacto
export const superAdminServiceFactory = ({
serverCfgDal,
userDal,
- authService
+ authService,
+ orgService
}: TSuperAdminServiceFactoryDep) => {
let serverCfg: TSuperAdmin;
@@ -70,7 +74,8 @@ export const superAdminServiceFactory = ({
lastName,
email,
superAdmin: true,
- isAccepted: true
+ isAccepted: true,
+ authMethods: [AuthMethod.EMAIL]
},
tx
);
@@ -92,6 +97,7 @@ export const superAdminServiceFactory = ({
);
return { user: newUser, enc: userEnc };
});
+ await orgService.createOrganization(userInfo.user.id, userInfo.user.email, "Admin Org");
await updateServerCfg({ initialized: true });
const token = await authService.generateUserTokens(userInfo.user, ip, userAgent);