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.
source share