mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-09-22 13:39:35 +00:00
Improve user alias check logic and header usage on resend code
This commit is contained in:
@@ -423,6 +423,7 @@ export const samlConfigServiceFactory = ({
|
||||
organizationSlug: organization.slug,
|
||||
authMethod: authProvider,
|
||||
hasExchangedPrivateKey: true,
|
||||
aliasId: userAlias.id,
|
||||
authType: UserAliasType.SAML,
|
||||
isUserCompleted,
|
||||
...(relayState
|
||||
|
||||
@@ -20,15 +20,12 @@ export const registerUserRouter = async (server: FastifyZodProvider) => {
|
||||
headers: z.object({
|
||||
referer: z.string().trim()
|
||||
}),
|
||||
body: z.object({
|
||||
username: z.string().trim()
|
||||
}),
|
||||
response: {
|
||||
200: z.object({})
|
||||
}
|
||||
},
|
||||
handler: async (req) => {
|
||||
await server.services.user.sendEmailVerificationCode(req.body.username, req.headers.referer);
|
||||
await server.services.user.sendEmailVerificationCode(req.headers.referer);
|
||||
return {};
|
||||
}
|
||||
});
|
||||
|
||||
@@ -54,18 +54,22 @@ export const userServiceFactory = ({
|
||||
permissionService,
|
||||
userAliasDAL
|
||||
}: TUserServiceFactoryDep) => {
|
||||
const sendEmailVerificationCode = async (username: string, referer: string) => {
|
||||
const sendEmailVerificationCode = async (referer: string) => {
|
||||
const url = new URL(referer);
|
||||
const refererToken = url.searchParams.get("token");
|
||||
if (!refererToken)
|
||||
throw new BadRequestError({ name: "Failed to send email verification code due to no token on referer" });
|
||||
const { authType, aliasId, username } = crypto.jwt().decode(refererToken) as {
|
||||
authType: string;
|
||||
aliasId: string;
|
||||
username: string;
|
||||
};
|
||||
// akhilmhdh: case sensitive email resolution
|
||||
const users = await userDAL.findUserByUsername(username);
|
||||
const user = users?.length > 1 ? users.find((el) => el.username === username) : users?.[0];
|
||||
if (!user) throw new NotFoundError({ name: `User with username '${username}' not found` });
|
||||
let { isEmailVerified } = user;
|
||||
const url = new URL(referer);
|
||||
const refererToken = url.searchParams.get("token");
|
||||
if (!refererToken)
|
||||
throw new BadRequestError({ name: "Failed to send email verification code due to no token on referer" });
|
||||
const { authType } = crypto.jwt().decode(refererToken) as { authType: string };
|
||||
const userAlias = await userAliasDAL.findOne({ userId: user.id, aliasType: authType });
|
||||
const userAlias = await userAliasDAL.findOne({ userId: user.id, aliasType: authType, id: aliasId });
|
||||
if (userAlias) {
|
||||
isEmailVerified = userAlias.isEmailVerified;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user