https://github.com/kth/kth-node-ldap
A small promise wrapper and convenience functions for ldapjs
https://github.com/kth/kth-node-ldap
Last synced: 4 months ago
JSON representation
A small promise wrapper and convenience functions for ldapjs
- Host: GitHub
- URL: https://github.com/kth/kth-node-ldap
- Owner: KTH
- License: mit
- Created: 2016-09-21T20:33:30.000Z (over 9 years ago)
- Default Branch: main
- Last Pushed: 2024-12-01T04:36:22.000Z (over 1 year ago)
- Last Synced: 2024-12-07T00:41:23.092Z (over 1 year ago)
- Language: JavaScript
- Size: 1.28 MB
- Stars: 1
- Watchers: 18
- Forks: 0
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# kth-node-ldap
Convenience library on top of the [ldapts](https://www.npmjs.com/package/ldapts) client.
## Code Example LDAPTS
How to create client connection object and re-export relevant methods. In this example the file is named ldapImportClient.js
```javascript
const { createClient, search, searchOne } = require('kth-node-ldap')
const config = require('../configuration').server
const log = require('@kth/log')
// ldap client is used to find users and need to be exposed
const ldapClient = createClient({
url: config.ldap.uri,
timeout: 30 * 60 * 1000,
connectTimeout: config.ldap.connecttimeout,
bindDN: config.ldap.username,
bindCredentials: config.ldap.password,
})
module.exports = {
ldapClient,
ldapSearch: search,
ldapSearchOne: searchOne,
}
```
Using the client above, perform the search
```javascript
const { ldapClient, ldapSearch, ldapSearchOne } = require('./ldapImportClient')
// Get all users changed since 2020-03-01
try {
const base = 'DC=ldap,DC=example,DC=com'
const since = '20200301000000.0Z'
const query = {
scope: 'sub',
attributes: ['givenName', 'familyName', 'updatedOn'],
filter: `(&(whenChanged>=${since}))`,
}
const usersArray = await ldapSearch(ldapClient, base, query)
for (const user of usersArray) {
// Do what you have to do..
}
} catch (err) {
log.error('Could not query LDAP ', { err: e })
}
// Find a single user
try {
const base = 'DC=ldap,DC=example,DC=com'
const username = 'paddy'
const query = {
scope: 'sub',
attributes: ['givenName', 'familyName', 'updatedOn'],
filter: '(&(ugUsername=${username}))',
}
const user = await ldapSearchOne(ldapClient, base, query)
// Do what you have to do..
} catch (err) {
log.error('Could not query LDAP ', { err: e })
}
```