Giter Club home page Giter Club logo

ldapjs-client's Introduction

LDAP js client

'Build status'

node >= 8.0

No jdapjs (https://www.npmjs.com/package/ldapjs) as dependency.

Why: because jdapjs is not maintained for more than two years.

Installation

npm install ldapjs-client

Usage

To create a new client:

var LdapClient = require('ldapjs-client');
var client = new LdapClient({ url: 'ldap://127.0.0.1:389' });
Attribute Type Description
url String A valid LDAP URL (proto/host/port only)
timeout Number Milliseconds client should let operations live for before timing out (Default: Infinity)
tlsOptions Object Additional options passed to TLS connection layer when connecting via ldaps:// (See: The TLS docs for node.js)

add

try {
  const entry = {
    cn: 'foo',
    sn: 'bar',
    email: ['[email protected]', '[email protected]'],
    objectclass: 'fooPerson'
  };

  await client.add('cn=foo, o=example', entry);
} catch (e) {
  console.log('Add failed');
}

bind

try {
  await client.bind('username', 'password');
} catch (e) {
  console.log('Bind failed');
}

del

try {
  await client.del('cn=foo, o=example');
} catch (e) {
  console.log(e);
}

modify

try {
  const change = {
    operation: 'add', // add, delete, replace
    modification: {
      pets: ['cat', 'dog']
    }
  };

  await client.modify('cn=foo, o=example', change);
} catch (e) {
  console.log(e);
}

modifyDN

try {
  await client.modifyDN('cn=foo, o=example', 'cn=bar');
} catch (e) {
  console.log(e);
}

search

try {
  const options = {
    filter: '(&(l=Seattle)(email=*@foo.com))',
    scope: 'sub',
    attributes: ['dn', 'sn', 'cn']
  };

  const entries = await client.search('o=example', options);
} catch (e) {
  console.log(e);
}
Attribute Type Description
scope String One of base, one, or sub. Defaults to base
filter String A string version of an LDAP filter. Defaults to (objectclass=*)
attributes Array of String attributes to select and return. Defaults to the empty set, which means all attributes
sizeLimit Number the maximum number of entries to return. Defaults to 0 (unlimited)
timeLimit Number the maximum amount of time the server should take in responding, in seconds. Defaults to 10. Lots of servers will ignore this
typesOnly Boolean on whether you want the server to only return the names of the attributes, and not their values. Borderline useless. Defaults to false

unbind

try {
  await client.unbind();
} catch (e) {
  console.log(e);
}

destroy

try {
  await client.unbind();
} catch (e) {
  console.log(e);
}

Close connection if exists and destroy current client


Pull requests and suggestions are welcome!

License

MIT.

ldapjs-client's People

Contributors

zont avatar ifrias-fuze avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.