Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
var ldap = require('ldapjs');
var client = ldap.createClient({
url: 'ldap://10.10.0.10'
});
client.bind('user@donaim', 'pw', function(error) {
if (error) {
console.log('Wrong password');
client.unbind(function(error) {
if (error) {
console.log(error.message);
}
});
} else {
console.log('Login ok');
}
var opts = {
filter: '(objectclass=user)',
scope: 'sub',
attributes: ['sn', 'cn', 'mail']
};
client.search('OU=Sites,DC=nixsolutions,DC=com', opts, function(err, res) {
if (err) {
console.log(err);
}
res.on('searchEntry', function(entry) {
console.log('entry: ' + JSON.stringify(entry.object));
});
res.on('searchReference', function(referral) {
console.log('referral: ' + referral.uris.join());
});
res.on('error', function(err) {
console.error('error: ' + err.message);
});
res.on('end', function(result) {
console.log('status: ' + result.status);
client.unbind(function(error) {
if (error) {
console.log(error.message);
}
});
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment