forked from auth0/auth0-ldap-endpoint
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test-client.js
40 lines (35 loc) · 1.09 KB
/
test-client.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
var ldap = require('ldapjs');
var client = ldap.createClient({
url: 'ldap://127.0.0.1:1389'
});
client.bind('[email protected],OU=Username-Password-Authentication', 'MyPassword', function(err) {
if (err) {
console.log('Bind Error:', JSON.stringify(err, null, 2));
return client.unbind(function(err) {
if (err) {
console.log(err);
}
});
}
console.log('Bind success.');
var opts = {
filter: '([email protected])',
scope: 'sub',
attributes: ['dn', 'sn', 'cn']
};
console.log(`Searching for: ${JSON.stringify(opts, null, 2)}`);
client.search('OU=Username-Password-Authentication', opts, function(err, res) {
res.on('searchEntry', function(entry) {
console.log('Found: ' + 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('Search Done. Status: ' + result.status);
});
});
});