i am new to ldap. i am using ldapauth.js to authenticate the credentials.
i have used ldapauth npm for authentucation.
/*--------------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 the error message.
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 in figuring out what is wrong.
Thanks for your time
It looks like you have mistyped the port number, the default LDAP port is 389 but here you are using url: "ldap://0.0.0.0:1389". I assume that you are using the real IP in you code.
You are running a LDAP client and a LDAP server in the same process. Somehow I doubt that this is what you want to do. Usually you would either create a server process to provide the authentication service, or you'd be the client trying to authenticate your users against a central LDAP directory.
The error message also shows that the server doesn't have any data - naturally, as you started it and didn't provide any data.
I'm guessing you just want to ask your central (already running somewhere) LDAP server to authenticate the users that 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 the config in the express app in my parallel question about performance here