ldapjs-promise
Version:
A simple promise wrapper around ldapjs.
77 lines (60 loc) • 2.28 kB
Markdown
[![Build Status][travis_image_url]](https://travis-ci.org/wslyhbb/node-ldapjs-promise)
[]: https://travis-ci.org/wslyhbb/node-ldapjs-promise.svg?branch=master
LDAP Client and Server API for node.js with Promise support.
[]: https://www.npmjs.com/package/ldapjs
This is a simple wrapper around [ldapjs] for basic operations.
npm install --save ldapjs-promise
For full docs, head on over to <http://ldapjs.org>.
The methods signatures are the same except instead of callbacks they return promises.
```javascript
const ldap = require('ldapjs-promise');
const client = ldap.createClient({
url: 'ldap://127.0.0.1:1389'
});
await client.bind(dn, password);
```
The [ldapjs] authors made the search method a special method that returns an
<code>EventEmitter</code> so the user can handle each
<code>searchEntry</code> as it is returned. Since this library is just wrapping
[], it does not make any assumptions and returns the same <code>EventEmitter</code>.
In order to await all of the results you could:
```javascript
const results = client.search(base, options, controls).then(response => {
const entries = [];
let referrals = [];
return 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 <code>searchReturnAll</code> has been added
that does this.
```javascript
const results = await client.searchReturnAll(base, options, controls);
for (let entry of results.entries) {
...
}
```
+ `findUser(base, username, options)`
+ `userInGroup(base, username, groupName)`