fix(login): Add Organization Scoping to IDP Auto-Linking (#10931)

This PR fixes an issue in the IDP auto-linking feature where user
searches were performed globally instead of being scoped to the current
organization context. This could result in IDP links being created for
users in unintended organizations.

# Which Problems Are Solved

When IDP auto-linking was enabled (by email or username), the system
would search for existing users across all organizations instead of
restricting the search to the current organization context.

# How the Problems Are Solved

Added organization scoping to all three auto-linking code paths

(cherry picked from commit 2ad5cf141f)
This commit is contained in:
Max Peintner
2025-10-21 10:56:34 +02:00
committed by Livio Spring
parent 8b1aa8cbec
commit b94c7845a1

View File

@@ -179,22 +179,21 @@ export default async function Page(props: {
const email = addHumanUser?.email?.email;
if (options.autoLinking === AutoLinkingOption.EMAIL && email) {
foundUser = await listUsers({ serviceUrl, email }).then((response) => {
foundUser = await listUsers({ serviceUrl, email, organizationId: organization }).then((response) => {
return response.result ? response.result[0] : null;
});
} else if (options.autoLinking === AutoLinkingOption.USERNAME) {
foundUser = await listUsers(
options.autoLinking === AutoLinkingOption.USERNAME
? { serviceUrl, userName: idpInformation.userName }
: { serviceUrl, email },
).then((response) => {
return response.result ? response.result[0] : null;
});
foundUser = await listUsers({ serviceUrl, userName: idpInformation.userName, organizationId: organization }).then(
(response) => {
return response.result ? response.result[0] : null;
},
);
} else {
foundUser = await listUsers({
serviceUrl,
userName: idpInformation.userName,
email,
organizationId: organization,
}).then((response) => {
return response.result ? response.result[0] : null;
});