'use strict';
process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0";
var ldap = require('ldapjs');
const assert = require('assert');
var creds = {
url: "ldap://*****************",
};
var baseDN = "OU=****,OU=Utilisateurs,OU=****,OU=****,OU=****,DC=***,DC=***,DC=local";
var user = 'LASTNAME Firstname';
var password = 'password';
var fullDN = 'uid=' + user + ',' + baseDN;
var opts = {
filter: "(&(objectClass=user)(email=*****@***))",
scope: "sub",
password: "password",
client: "email"
};
function authDN(user, baseDN, password, cb) {
console.log('binding done');
client.bind(baseDN,password, function (err) {
client.unbind();
cb(err === null, err);
console.log('binding failed');
});
}
function output(res, err) {
if (res) {
console.log('success');
console.log(res);
} else {
console.log(['Error',err.code, err.dn, err.message ]);
}
}
var client = ldap.createClient(creds);
authDN(client, 'server instance name', 'password', output);
//serach method
client.search('CN=LASTNAME Firstname,OU=****,OU=Utilisateurs,OU=****,OU=****,OU=****,DC=***,DC=***,DC=local', opts, function(err, res) {
assert.ifError(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.put(Context.REFERRAL,"follow");
res.on('error', function(err) {
console.error('error: ' + err.message);
});
res.on('end', function(result) {
console.log('status: ' + result.status);
console.log('result: ' + result);
process.exit(1);
});
});