Skip to content

Instantly share code, notes, and snippets.

@josser
Created July 26, 2016 15:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save josser/b164012c65e4bd9112b8ebab6a005355 to your computer and use it in GitHub Desktop.
Save josser/b164012c65e4bd9112b8ebab6a005355 to your computer and use it in GitHub Desktop.
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