Check token source before throwing an error for auth enforced scenarios

This commit is contained in:
Carlos Monastyrski
2025-08-31 13:24:08 -03:00
parent 5fffa17c30
commit e04e11f597

View File

@@ -453,8 +453,13 @@ export const authLoginServiceFactory = ({
const selectedOrg = await orgDAL.findById(organizationId);
// Check if authEnforced is true, if that's the case, throw an error
if (selectedOrg.authEnforced) {
// Check if authEnforced is true and the current auth method is not an enforced method
if (
selectedOrg.authEnforced &&
!isAuthMethodSaml(decodedToken.authMethod) &&
decodedToken.authMethod !== AuthMethod.OIDC &&
decodedToken.authMethod !== AuthMethod.GOOGLE
) {
throw new BadRequestError({
message: "Authentication is required by your organization before you can log in."
});