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

This commit is contained in:
Akhil Mohan
2024-01-14 20:31:49 +05:30
parent 3519412639
commit deb8e74749
5 changed files with 71 additions and 25 deletions

View File

@@ -245,7 +245,8 @@ export const registerRoutes = async (
const superAdminService = superAdminServiceFactory({
userDal,
authService: loginService,
serverCfgDal: superAdminDal
serverCfgDal: superAdminDal,
orgService
});
const apiKeyService = apiKeyServiceFactory({ apiKeyDal, userDal });

View File

@@ -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" };
}
});
};

View File

@@ -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,

View File

@@ -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;
});

View File

@@ -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);