vesse / node-ldapauth-fork

Simple node.js module to authenticate against an LDAP server
Other
127 stars 79 forks source link

TypeError: Cannot read property 'on' of undefined #22

Closed matthieusieben closed 9 years ago

matthieusieben commented 9 years ago

I get the following error when trying to use ldapauth on a (tls) secured ldap server. Not sure this is related to my config, to ldapauth-fork or to ldapjs.

~/node_modules/ldapauth-fork/node_modules/ldapjs/lib/client/client.js:111
  closeSocket.on('close', function onClose(had_err) {
             ^
TypeError: Cannot read property 'on' of undefined
    at setupSocket (~/node_modules/ldapauth-fork/node_modules/ldapjs/lib/client/client.js:111:14)
    at Client._connect (~/node_modules/ldapauth-fork/node_modules/ldapjs/lib/client/client.js:742:3)
    at new Client (~/node_modules/ldapauth-fork/node_modules/ldapjs/lib/client/client.js:247:22)
    at Object.createClient (~/node_modules/ldapauth-fork/node_modules/ldapjs/lib/client/index.js:60:12)
    at new LdapAuth (~/node_modules/ldapauth-fork/lib/ldapauth.js:129:28)

My config is as follows

var options = {
  "url": "ldaps://ldap.MY_DOMAIN.com:636",
  "bindDn": "cn=master-read,dc=MY_DOMAIN,dc=com",
  "bindCredentials": "MyLdapPassword",
  "searchBase": "dc=MY_DOMAIN,dc=com",
  "searchFilter": "(&(objectClass=inetOrgPerson)(mailRoutingAddress={{username}}))",
  "tlsOptions": {
    "cert": "-----BEGIN CERTIFICATE-----\nNOT_SHOWN\n-----END CERTIFICATE-----"
  }
};

I can get all this to work if I replace line 108 of ldapjs/lib/client/client.js by:

var closeSocket = (opts.secure ? socket.socket || socket : socket);

Version of node: 0.12.0

vesse commented 9 years ago

Yeah that happens since this module depends on the latest released version of ldapjs. I've been waiting for a new release as I prefer not to depend on random git commit. Meanwhile you can work around this by using the latest ldapjs, ie. set dependencies like this:

{
  "dependencies": {
    "ldapjs": "mcavage/node-ldapjs",
    "ldapauth-fork": "2.3.2",
  }
}

Probably need to delete node_modules/ldapauth-fork first and then run npm install.