mirror of
https://github.com/andwati/zitadel.git
synced 2026-12-06 02:48:50 +00:00
fix(login): idp redirect (#10482)
This PR fixes an issue where a user was not redirected to an IDP correctly if the user has entered the loginname and has an IDP as single auth method
This commit is contained in:
@@ -201,35 +201,21 @@ export async function sendLoginname(command: SendLoginnameCommand) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// compare with the concatenated suffix when set
|
// compare with the concatenated suffix when set
|
||||||
const concatLoginname = command.suffix
|
const concatLoginname = command.suffix ? `${command.loginName}@${command.suffix}` : command.loginName;
|
||||||
? `${command.loginName}@${command.suffix}`
|
|
||||||
: command.loginName;
|
|
||||||
|
|
||||||
const humanUser =
|
const humanUser = potentialUsers[0].type.case === "human" ? potentialUsers[0].type.value : undefined;
|
||||||
potentialUsers[0].type.case === "human"
|
|
||||||
? potentialUsers[0].type.value
|
|
||||||
: undefined;
|
|
||||||
|
|
||||||
// recheck login settings after user discovery, as the search might have been done without org scope
|
// recheck login settings after user discovery, as the search might have been done without org scope
|
||||||
if (
|
if (userLoginSettings?.disableLoginWithEmail && userLoginSettings?.disableLoginWithPhone) {
|
||||||
userLoginSettings?.disableLoginWithEmail &&
|
|
||||||
userLoginSettings?.disableLoginWithPhone
|
|
||||||
) {
|
|
||||||
if (user.preferredLoginName !== concatLoginname) {
|
if (user.preferredLoginName !== concatLoginname) {
|
||||||
return { error: "User not found in the system!" };
|
return { error: "User not found in the system!" };
|
||||||
}
|
}
|
||||||
} else if (userLoginSettings?.disableLoginWithEmail) {
|
} else if (userLoginSettings?.disableLoginWithEmail) {
|
||||||
if (
|
if (user.preferredLoginName !== concatLoginname || humanUser?.phone?.phone !== command.loginName) {
|
||||||
user.preferredLoginName !== concatLoginname ||
|
|
||||||
humanUser?.phone?.phone !== command.loginName
|
|
||||||
) {
|
|
||||||
return { error: "User not found in the system!" };
|
return { error: "User not found in the system!" };
|
||||||
}
|
}
|
||||||
} else if (userLoginSettings?.disableLoginWithPhone) {
|
} else if (userLoginSettings?.disableLoginWithPhone) {
|
||||||
if (
|
if (user.preferredLoginName !== concatLoginname || humanUser?.email?.email !== command.loginName) {
|
||||||
user.preferredLoginName !== concatLoginname ||
|
|
||||||
humanUser?.email?.email !== command.loginName
|
|
||||||
) {
|
|
||||||
return { error: "User not found in the system!" };
|
return { error: "User not found in the system!" };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -270,11 +256,7 @@ export async function sendLoginname(command: SendLoginnameCommand) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (command.organization || session.factors?.user?.organizationId) {
|
if (command.organization || session.factors?.user?.organizationId) {
|
||||||
params.append(
|
params.append("organization", command.organization ?? (session.factors?.user?.organizationId as string));
|
||||||
"organization",
|
|
||||||
command.organization ??
|
|
||||||
(session.factors?.user?.organizationId as string),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return { redirect: `/verify?` + params };
|
return { redirect: `/verify?` + params };
|
||||||
@@ -286,8 +268,7 @@ export async function sendLoginname(command: SendLoginnameCommand) {
|
|||||||
case AuthenticationMethodType.PASSWORD: // user has only password as auth method
|
case AuthenticationMethodType.PASSWORD: // user has only password as auth method
|
||||||
if (!userLoginSettings?.allowUsernamePassword) {
|
if (!userLoginSettings?.allowUsernamePassword) {
|
||||||
return {
|
return {
|
||||||
error:
|
error: "Username Password not allowed! Contact your administrator for more information.",
|
||||||
"Username Password not allowed! Contact your administrator for more information.",
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -298,10 +279,7 @@ export async function sendLoginname(command: SendLoginnameCommand) {
|
|||||||
// TODO: does this have to be checked in loginSettings.allowDomainDiscovery
|
// TODO: does this have to be checked in loginSettings.allowDomainDiscovery
|
||||||
|
|
||||||
if (command.organization || session.factors?.user?.organizationId) {
|
if (command.organization || session.factors?.user?.organizationId) {
|
||||||
paramsPassword.append(
|
paramsPassword.append("organization", command.organization ?? session.factors?.user?.organizationId);
|
||||||
"organization",
|
|
||||||
command.organization ?? session.factors?.user?.organizationId,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (command.requestId) {
|
if (command.requestId) {
|
||||||
@@ -315,8 +293,7 @@ export async function sendLoginname(command: SendLoginnameCommand) {
|
|||||||
case AuthenticationMethodType.PASSKEY: // AuthenticationMethodType.AUTHENTICATION_METHOD_TYPE_PASSKEY
|
case AuthenticationMethodType.PASSKEY: // AuthenticationMethodType.AUTHENTICATION_METHOD_TYPE_PASSKEY
|
||||||
if (userLoginSettings?.passkeysType === PasskeysType.NOT_ALLOWED) {
|
if (userLoginSettings?.passkeysType === PasskeysType.NOT_ALLOWED) {
|
||||||
return {
|
return {
|
||||||
error:
|
error: "Passkeys not allowed! Contact your administrator for more information.",
|
||||||
"Passkeys not allowed! Contact your administrator for more information.",
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -328,13 +305,19 @@ export async function sendLoginname(command: SendLoginnameCommand) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (command.organization || session.factors?.user?.organizationId) {
|
if (command.organization || session.factors?.user?.organizationId) {
|
||||||
paramsPasskey.append(
|
paramsPasskey.append("organization", command.organization ?? session.factors?.user?.organizationId);
|
||||||
"organization",
|
|
||||||
command.organization ?? session.factors?.user?.organizationId,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return { redirect: "/passkey?" + paramsPasskey };
|
return { redirect: "/passkey?" + paramsPasskey };
|
||||||
|
|
||||||
|
case AuthenticationMethodType.IDP:
|
||||||
|
const resp = await redirectUserToIDP(userId);
|
||||||
|
|
||||||
|
if (resp?.error) {
|
||||||
|
return { error: resp.error };
|
||||||
|
}
|
||||||
|
|
||||||
|
return resp;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// prefer passkey in favor of other methods
|
// prefer passkey in favor of other methods
|
||||||
@@ -349,20 +332,13 @@ export async function sendLoginname(command: SendLoginnameCommand) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (command.organization || session.factors?.user?.organizationId) {
|
if (command.organization || session.factors?.user?.organizationId) {
|
||||||
passkeyParams.append(
|
passkeyParams.append("organization", command.organization ?? session.factors?.user?.organizationId);
|
||||||
"organization",
|
|
||||||
command.organization ?? session.factors?.user?.organizationId,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return { redirect: "/passkey?" + passkeyParams };
|
return { redirect: "/passkey?" + passkeyParams };
|
||||||
} else if (
|
} else if (methods.authMethodTypes.includes(AuthenticationMethodType.IDP)) {
|
||||||
methods.authMethodTypes.includes(AuthenticationMethodType.IDP)
|
|
||||||
) {
|
|
||||||
return redirectUserToIDP(userId);
|
return redirectUserToIDP(userId);
|
||||||
} else if (
|
} else if (methods.authMethodTypes.includes(AuthenticationMethodType.PASSWORD)) {
|
||||||
methods.authMethodTypes.includes(AuthenticationMethodType.PASSWORD)
|
|
||||||
) {
|
|
||||||
// user has no passkey setup and login settings allow passkeys
|
// user has no passkey setup and login settings allow passkeys
|
||||||
const paramsPasswordDefault = new URLSearchParams({
|
const paramsPasswordDefault = new URLSearchParams({
|
||||||
loginName: session.factors?.user?.loginName,
|
loginName: session.factors?.user?.loginName,
|
||||||
@@ -373,10 +349,7 @@ export async function sendLoginname(command: SendLoginnameCommand) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (command.organization || session.factors?.user?.organizationId) {
|
if (command.organization || session.factors?.user?.organizationId) {
|
||||||
paramsPasswordDefault.append(
|
paramsPasswordDefault.append("organization", command.organization ?? session.factors?.user?.organizationId);
|
||||||
"organization",
|
|
||||||
command.organization ?? session.factors?.user?.organizationId,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
@@ -387,19 +360,13 @@ export async function sendLoginname(command: SendLoginnameCommand) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// user not found, check if register is enabled on instance / organization context
|
// user not found, check if register is enabled on instance / organization context
|
||||||
if (
|
if (loginSettingsByContext?.allowRegister && !loginSettingsByContext?.allowUsernamePassword) {
|
||||||
loginSettingsByContext?.allowRegister &&
|
|
||||||
!loginSettingsByContext?.allowUsernamePassword
|
|
||||||
) {
|
|
||||||
const resp = await redirectUserToSingleIDPIfAvailable();
|
const resp = await redirectUserToSingleIDPIfAvailable();
|
||||||
if (resp) {
|
if (resp) {
|
||||||
return resp;
|
return resp;
|
||||||
}
|
}
|
||||||
return { error: "User not found in the system" };
|
return { error: "User not found in the system" };
|
||||||
} else if (
|
} else if (loginSettingsByContext?.allowRegister && loginSettingsByContext?.allowUsernamePassword) {
|
||||||
loginSettingsByContext?.allowRegister &&
|
|
||||||
loginSettingsByContext?.allowUsernamePassword
|
|
||||||
) {
|
|
||||||
let orgToRegisterOn: string | undefined = command.organization;
|
let orgToRegisterOn: string | undefined = command.organization;
|
||||||
|
|
||||||
if (
|
if (
|
||||||
@@ -416,8 +383,7 @@ export async function sendLoginname(command: SendLoginnameCommand) {
|
|||||||
serviceUrl,
|
serviceUrl,
|
||||||
domain: suffix,
|
domain: suffix,
|
||||||
});
|
});
|
||||||
const orgToCheckForDiscovery =
|
const orgToCheckForDiscovery = orgs.result && orgs.result.length === 1 ? orgs.result[0].id : undefined;
|
||||||
orgs.result && orgs.result.length === 1 ? orgs.result[0].id : undefined;
|
|
||||||
|
|
||||||
const orgLoginSettings = await getLoginSettings({
|
const orgLoginSettings = await getLoginSettings({
|
||||||
serviceUrl,
|
serviceUrl,
|
||||||
|
|||||||
Reference in New Issue
Block a user