nodejs passport ldapauth "Cannot read 'on' property of undefined"

ldap, node.js, passport.js, ssl

Solution

Finally, I could solve the issue.

The ldapjs version used in ldapauth-fork, can't work with an ldaps url.

The solution was:

Delete the ldapjs from ldapauth-fork using in the node_modules directory under ldapauth-fork (under other node_modules directory under passport-ldap in the node_modules for my user !!!!!!) the following command:

npm rm ldapjs

Install the new version from github using:

npm install git://github.com/mcavage/node-ldapjs.git

FDO.

Problem

I'm trying to authenticate to an LDAP server using passport-ldapauth and express. The authentication using an ldap url (ldap://myserver...) works OK, but with ldaps I get: ``` TypeError: Cannot read property 'on' of undefined at setupSocket (...\ldapauth-fork\node_modules\ldapjs\lib\client\client.js:111:14) at Client._connect (...\ldapauth-fork\node_modules\ldapjs\lib\client\client.js:742:3) at new Client (...\ldapauth-fork\node_modules\ldapjs\lib\client\client.js:247:22) at Object.createClient (...\ldapauth-fork\node_modules\ldapjs\lib\client\index.js:60:12) at new LdapAuth (...\ldapauth-fork\lib\ldapauth.js:129:28) at handleAuthentication (...\passport-ldapauth\lib\passport-ldapauth\strategy.js:140:10) at Strategy.authenticate (...\passport-ldapauth\lib\passport-ldapauth\strategy.js:175:33) at attempt (...\passport\lib\middleware\authenticate.js:341:16) at authenticate (...\passport\lib\middleware\authenticate.js:342:7) at Layer.handle [as handle_request] (...\express\lib\router\layer.js:82:5) ``` My code is, basically, this: ``` ... passport.use(new LdapStrategy({ server: { url: 'ldaps://myserver:636', searchBase: '...', searchFilter: '(uid={{username}})', tlsOptions: { ca: [ fs.readFileSync('myCAcert.pem') ] } }, session: false, usernameField:'u', passwordField:'p' }, function(user, done) { console.log("Interna: \nOK"); console.log("u:"); console.log(user.cn); return done(null, user); })); app.use('/login',passport.authenticate('ldapauth', { session:false, successRedirect:'/accessed', failureRedirect: '/accessfail' } )); app.use('/accessed',function (req,res,next){ res.send("User OK"); }); app.use('/accessfail',function (req,res,next){ res.send("User MAL !!!!!!!"); }); app.listen(3336); ``` My library versions are: ``` express@4.11.2, passport@0.2.1,passport-ldapauth@0.3.0 ``` Someone can help me? Thanks.

Original source