Skip to content
This repository has been archived by the owner on May 14, 2024. It is now read-only.

LDAP search return empty array for every subsequent search after the first search. #955

Open
skbhagat0502 opened this issue Nov 23, 2023 · 1 comment

Comments

@skbhagat0502
Copy link

const ldapLogin = async (
request: Request,
response: Response,
next: NextFunction
) => {
const { email, password } = request.body;
const userDN = uid=${email},${ldapConfig.userBaseDN};
const SearchOptions: SearchOptions = {
filter: uid=${email},
scope: "sub",
attributes: ["cn", "sn", "uid"],
};
try {
const { searchEntries } = await client.search(
ldapConfig.userBaseDN,
SearchOptions
);
await client.bind(userDN, password);
const token = generateToken(email);
const authResponse = constructAuthResponse(searchEntries[0], token);
response.send(authResponse);
} catch (error) {
if (error instanceof InvalidCredentialsError) {
return next(
new errors.ValidationError(
[
{
message: INVALID_CREDENTIALS_ERROR.MESSAGE,
code: INVALID_CREDENTIALS_ERROR.CODE,
param: INVALID_CREDENTIALS_ERROR.PARAM,
},
],
INVALID_CREDENTIALS_ERROR.MESSAGE
)
);
} else if (error instanceof NoSuchObjectError) {
return next(
new errors.NotFoundError(
USER_NOT_FOUND_ERROR.MESSAGE,
USER_NOT_FOUND_ERROR.CODE,
USER_NOT_FOUND_ERROR.PARAM
)
);
} else {
console.error(error);
response.status(500).send("Internal Server Error");
}
}
}; Here is the code of my login controller for ldap auth. I get array with data of the user for the first time only and for every subsequent search after the first I get [] as the response.

@jsumners
Copy link
Member

Please provide a minimal reproducible example (MRE). Doing so will help us diagnose your issue. It should be the bare minimum code needed to trigger the issue, and easily runnable without any changes or extra code. Please review the integration tests, e.g. issue-940.test.js, for examples of good MREs.

You may use a GitHub repository to host the code if it is too much to fit in a code block (or two).

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants