Open skbhagat0502 opened 12 months ago
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).
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.