node-ldapjs icon indicating copy to clipboard operation
node-ldapjs copied to clipboard

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

Open skbhagat0502 opened this issue 1 year ago • 1 comments

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.

skbhagat0502 avatar Nov 23 '23 09:11 skbhagat0502

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).

jsumners avatar Nov 23 '23 13:11 jsumners