LDAP JS auth error

I am new to ldap. I am using ldapauth.js to authenticate credentials.

I have used ldapauth npm for authentication.

/ * -------------- LDAP_AUTH -------------- * /

var ldap = require('ldapjs');
var LdapAuth = require('ldapauth');
var server = ldap.createServer();

server.search('o=example', function(req, res, next) {
  var obj = {
    dn: req.dn.toString(),
    attributes: {
      objectclass: ['organization', 'top'],
      o: 'example'
    }
  };

  if (req.filter.matches(obj.attributes))
    res.send(obj);

  res.end();
});

server.listen(1389, function() {
  console.log('LDAP server listening at %s', server.url);
});



var options = {
    url: "ldap://0.0.0.0:1389",
    adminDn: "uid=myadminusername,ou=users,o=example",
    adminPassword: "mypassword",
    searchBase: "ou=users,o=example",
    searchFilter: "(uid={{username}})"
};
var auth = new LdapAuth(options);

auth.authenticate('myadminusername', 'mypassword', function(err, user) { console.log('err'); 
    console.log(err);
console.log(err.message);
console.log('user');
console.log(user);
});

auth.close(function(err) { console.log('errorr'); })

      

in the console I am getting an error.

LDAP server listening at ldap://0.0.0.0:1389
err
{ dn: [Getter],
  code: [Getter],
  name: [Getter],
  message: [Getter] }
No tree found for: uid=myadminusername, ou=users, o=example
user
undefined

      

Please help me figure out what is wrong.

thank you for your time

+3


source to share


2 answers


It looks like you misplaced the port number, the default LDAP port 389

, but here you are using url: "ldap://0.0.0.0:1389"

. I am assuming you are using real IP in your code.



+1


source


The same process runs the LDAP client and LDAP server. For some reason I doubt this is what you want to do. Typically, you should either create a server process to provide an authentication service, or you will try to authenticate your users against the central LDAP directory.

The error message also indicates that the server has no data - naturally when you started it and did not provide any data.



I assume you just want to ask your central (already running somewhere) LDAP server to authenticate users who want to use your server / api / website, then the second part of what you are doing is right. ONLY use the instructions found here

See config in express app in my side-by-side performance question here

+1


source







All Articles