Socket
Socket
Sign inDemoInstall

kth-node-ldap

Package Overview
Dependencies
Maintainers
1
Versions
43
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

kth-node-ldap

Adds a Promise-based API on top of ldapjs as well as a filter builder.


Version published
Weekly downloads
131
increased by25.96%
Maintainers
1
Weekly downloads
 
Created
Source

kth-node-ldap Build Status

Convenience library on top of the ldapjs client.

Code Example

It's highly recommended that you use co with this library.

var ldap = require('kth-node-ldap')
var co = require('co')

var client = ldap.createClient({
  // same configuration as the usual ldapjs client
  url: 'ldaps://ldap.example.com',
  bindDN: 'user@ldap.example.com',
  bindCredentials: 'secret'
})

// you can access the ldapjs client through client._client

// the library comes with helpers to build ldap filters:
var F = ldap.filters
var filter

// 1. match all entries with this exact memberOf value
filter = F.eq('memberOf', 'OU=users,DC=ldap,DC=example,DC=com')
// 2. or match all entries with a givenName starting with 'a', 'b', or 'c'
filter = F.orAll('givenName', ['a*', 'b*', 'c*'])
// 3. combine for more complex filters
filter = F.ne('givenName', 'f*')
  .and(F.eq('familyName', 'g*'))

co(function * () {
  var res = yield client.search('DC=ldap,DC=example,DC=com', {
    scope: 'sub',
    attributes: [ 'givenName', 'familyName', 'updatedOn' ],
    filter: filter,
    paged: {
      pageSize: 250,
      // pagePause will be forced to true
      // otherwise this library will not work
      pagePause: true
    }
  })
  
  // access the ldapjs search result through res._res
  
  // res.each() will handle paging and more
  // all that's required is a function which returns a Promise
  // (co.wrap() does this for us)
  yield res.each(co.wrap(function * (entry) {
    // do something with entry
    var user = {
      givenName: entry.object.givenName,
      familyName: entry.object.familyName,
      // this library also provides a helper to convert dates
      // assuming updatedOn is a lexical utc date (e.g. '20160921123456.0Z')
      updatedOn: ldap.utils.toDate(entry.object.updatedOn)
    }
    
    // e.g. yield _saveToDb(user)
    
    // NOTE: if you do a bulk insert here, make sure you execute
    // the bulk every so often in case the search result contains
    // thousands of entries...
  }))
  
  client.close()
}).catch(function (err) {
  console.error(err)
  process.exit(1)
})

Keywords

FAQs

Package last updated on 16 May 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc