mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-05 17:26:36 +00:00
Patch new org creation condition on SAML account signup, enable users to toggle auth methods regardless of what org they are in
This commit is contained in:
@@ -120,8 +120,10 @@ export const authSignupServiceFactory = ({
|
|||||||
throw new Error("Failed to complete account for complete user");
|
throw new Error("Failed to complete account for complete user");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let organizationId;
|
||||||
if (providerAuthToken) {
|
if (providerAuthToken) {
|
||||||
validateProviderAuthToken(providerAuthToken, user.email);
|
const { orgId } = validateProviderAuthToken(providerAuthToken, user.email);
|
||||||
|
organizationId = orgId;
|
||||||
} else {
|
} else {
|
||||||
validateSignUpAuthorization(authorization, user.id);
|
validateSignUpAuthorization(authorization, user.id);
|
||||||
}
|
}
|
||||||
@@ -147,11 +149,7 @@ export const authSignupServiceFactory = ({
|
|||||||
return { info: us, key: userEncKey };
|
return { info: us, key: userEncKey };
|
||||||
});
|
});
|
||||||
|
|
||||||
const hasSamlEnabled = user?.authMethods?.some((authMethod) =>
|
if (!organizationId) {
|
||||||
[AuthMethod.OKTA_SAML, AuthMethod.AZURE_SAML, AuthMethod.JUMPCLOUD_SAML].includes(authMethod as AuthMethod)
|
|
||||||
);
|
|
||||||
|
|
||||||
if (!hasSamlEnabled) {
|
|
||||||
await orgService.createOrganization(user.id, user.email, organizationName);
|
await orgService.createOrganization(user.id, user.email, organizationName);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -175,7 +173,8 @@ export const authSignupServiceFactory = ({
|
|||||||
authTokenType: AuthTokenType.ACCESS_TOKEN,
|
authTokenType: AuthTokenType.ACCESS_TOKEN,
|
||||||
userId: updateduser.info.id,
|
userId: updateduser.info.id,
|
||||||
tokenVersionId: tokenSession.id,
|
tokenVersionId: tokenSession.id,
|
||||||
accessVersion: tokenSession.accessVersion
|
accessVersion: tokenSession.accessVersion,
|
||||||
|
organizationId
|
||||||
},
|
},
|
||||||
appCfg.AUTH_SECRET,
|
appCfg.AUTH_SECRET,
|
||||||
{ expiresIn: appCfg.JWT_AUTH_LIFETIME }
|
{ expiresIn: appCfg.JWT_AUTH_LIFETIME }
|
||||||
@@ -186,7 +185,8 @@ export const authSignupServiceFactory = ({
|
|||||||
authTokenType: AuthTokenType.REFRESH_TOKEN,
|
authTokenType: AuthTokenType.REFRESH_TOKEN,
|
||||||
userId: updateduser.info.id,
|
userId: updateduser.info.id,
|
||||||
tokenVersionId: tokenSession.id,
|
tokenVersionId: tokenSession.id,
|
||||||
refreshVersion: tokenSession.refreshVersion
|
refreshVersion: tokenSession.refreshVersion,
|
||||||
|
organizationId
|
||||||
},
|
},
|
||||||
appCfg.AUTH_SECRET,
|
appCfg.AUTH_SECRET,
|
||||||
{ expiresIn: appCfg.JWT_REFRESH_LIFETIME }
|
{ expiresIn: appCfg.JWT_REFRESH_LIFETIME }
|
||||||
|
|||||||
@@ -30,15 +30,6 @@ export const userServiceFactory = ({ userDAL }: TUserServiceFactoryDep) => {
|
|||||||
const user = await userDAL.findById(userId);
|
const user = await userDAL.findById(userId);
|
||||||
if (!user) throw new BadRequestError({ name: "Update auth methods" });
|
if (!user) throw new BadRequestError({ name: "Update auth methods" });
|
||||||
|
|
||||||
const hasSamlEnabled = user?.authMethods?.some((method) =>
|
|
||||||
[AuthMethod.OKTA_SAML, AuthMethod.AZURE_SAML, AuthMethod.JUMPCLOUD_SAML].includes(method as AuthMethod)
|
|
||||||
);
|
|
||||||
if (hasSamlEnabled)
|
|
||||||
throw new BadRequestError({
|
|
||||||
name: "Update auth method",
|
|
||||||
message: "Failed to update auth methods due to SAML SSO "
|
|
||||||
});
|
|
||||||
|
|
||||||
const updatedUser = await userDAL.updateById(userId, { authMethods });
|
const updatedUser = await userDAL.updateById(userId, { authMethods });
|
||||||
return updatedUser;
|
return updatedUser;
|
||||||
};
|
};
|
||||||
|
|||||||
-13
@@ -25,8 +25,6 @@ const authMethodOpts: AuthMethodOption[] = [
|
|||||||
{ label: "GitLab", value: AuthMethod.GITLAB, icon: faGitlab }
|
{ label: "GitLab", value: AuthMethod.GITLAB, icon: faGitlab }
|
||||||
];
|
];
|
||||||
|
|
||||||
const samlProviders = [AuthMethod.OKTA_SAML, AuthMethod.JUMPCLOUD_SAML, AuthMethod.AZURE_SAML];
|
|
||||||
|
|
||||||
const schema = yup.object({
|
const schema = yup.object({
|
||||||
authMethods: yup.array().required("Auth method is required")
|
authMethods: yup.array().required("Auth method is required")
|
||||||
});
|
});
|
||||||
@@ -56,17 +54,6 @@ export const AuthMethodSection = () => {
|
|||||||
}, [user]);
|
}, [user]);
|
||||||
|
|
||||||
const onAuthMethodToggle = async (value: boolean, authMethodOpt: AuthMethodOption) => {
|
const onAuthMethodToggle = async (value: boolean, authMethodOpt: AuthMethodOption) => {
|
||||||
const hasSamlEnabled = user.authMethods.some((authMethod: AuthMethod) =>
|
|
||||||
samlProviders.includes(authMethod)
|
|
||||||
);
|
|
||||||
|
|
||||||
if (hasSamlEnabled) {
|
|
||||||
createNotification({
|
|
||||||
text: "SAML authentication can only be configured in your organization settings",
|
|
||||||
type: "error"
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
const newAuthMethods = value
|
const newAuthMethods = value
|
||||||
? [...authMethods, authMethodOpt.value]
|
? [...authMethods, authMethodOpt.value]
|
||||||
: authMethods.filter((auth) => auth !== authMethodOpt.value);
|
: authMethods.filter((auth) => auth !== authMethodOpt.value);
|
||||||
|
|||||||
Reference in New Issue
Block a user