ldapjs-promise
v4.0.0
Published
LDAP client and server APIs
Readme
ldapjs-promise
LDAP Client and Server API for node.js with Promise support.
Originally this was a promisfyied ldapjs library. Due to ldapjs being decommissioned, the core was merged into the project so the core can be directly modified.
Installation
npm install --save ldapjs-promiseUsage
For full docs, head on over to https://wslyhbb.github.io/ldapjs-promise.github.io/.
The methods signatures are the same except instead of callbacks they return promises.
import { createClient } from 'ldapjs-promise';
const client = createClient({
url: 'ldap://127.0.0.1:1389'
});
await client.bind(dn, password);The search method returns an EventEmitter so the user can handle each searchEntry as it is returned.
In order to await all of the results you could:
const response = client.search(base, options, controls);
const entries = [];
let referrals = [];
const results = await new Promise((resolve, reject) => {
response.on('searchEntry', entry => {
entries.push(entry);
});
response.on('searchReference', referral => {
referrals = referrals.concat(referral.uris);
});
response.on('error', error => {
return reject(error);
})
response.on('end', result => {
if (result.status !== 0) {
return reject(result.status);
}
return resolve({
entries: entries,
referrals: referrals
});
});
});If this is exactly what you want, an extension method searchReturnAll does this.
const results = await client.searchReturnAll(base, options, controls);
for (let entry of results.entries) {
...
}Additional Methods
findUser(base, username, options)userInGroup(base, username, groupName)
