I'm trying to build one NodeJS server and planning to use the organization's Microsoft Active Directory for authentication.
I tried the same with many packages (activedirectory, activedirectory2, ldapjs etc.)
But none of them seems to work for me.
I'm supplying the LDAP URL and below is my code.
var ldapjs = require('ldapjs');
var config = { url: 'ldap://mycompany.com/dc=mycompany,dc=com'
,timeout: 10
,reconnect: {
"initialDelay": 100,
"maxDelay": 500,
"failAfter": 5
}
}
var username = "user_id@mycompany.com";
var password="password";
const ldapClient = ldapjs.createClient(config);
ldapClient.bind(username, password, function (err) {
console.log("Logging data...");
ldapClient.search('dc=mycompany,dc=com', function (err, search) {
if (err) {
console.log('ERROR: ' +JSON.stringify(err));
return;
}
search.on('searchEntry', function (err,entry) {
if (err) {
console.log('ERROR: ' +JSON.stringify(err));
return;
}
else{
var user = entry.object;
console.log("Done.");
return;
}
});
});
});
Sometimes it works, but for most of the times I keep on getting following error (may be when it chooses a different IP)
Error: connect ETIMEDOUT <ip address>:389
at Object.exports._errnoException (util.js:1018:11)
at exports._exceptionWithHostPort (util.js:1041:20)
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1090:14)
What puzzles me is; if I try with the same LDAP URL in my C# application, it works fine.
Is there a difference in the way .Net app uses it than the way NodeJS uses?
Can I change my code in some way to make it work?