Created
July 26, 2016 15:53
-
-
Save josser/b164012c65e4bd9112b8ebab6a005355 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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