Nodejs passport ldapauth "Unable to read 'on' property undefined"

I am trying to authenticate to an LDAP server using the passport ldapauth and express.

Authentication using ldap url (ldap: // myserver ...) works fine, 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:

  express@4.11.2 , passport@0.2.1 , passport-ldapauth@0.3.0 

Can anybody help me?

Thanks.

+6
source share
2 answers

Finally, I could solve the problem.

The ldapjs version used in ldapauth-fork cannot work with the ldaps url.

Decision:

  • Remove ldapjs from ldapauth-fork using the node_modules directory in the ldapauth-fork directory (in another node_modules directory in the-ldap passport in 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

PDO.

+5
source

This only happens when using Node 0.12 and io.js when using SSL, see the ldapjs issue . You can add an unreleased version dependency in your package.json projects:

 { "dependencies": { "ldapjs": "mcavage/node-ldapjs", "ldapauth-fork": "2.3.1" } } 
+2
source

Source: https://habr.com/ru/post/983126/


All Articles