Code Monkey home page Code Monkey logo

promised-ldap's Introduction

promised-ldap

This library is a quick-n-dirty shim over ldapjs to add promises and easier authentication. It currently only supports the client interface.

Usage

To create a new client:

var LdapClient = require('promised-ldap');
var client = new LdapClient({url: 'ldap://127.0.0.1:389'});

The options argument to the constructor is identical to the options argument used in ldapjs for ldap.createClient. Please see the docs here.

It supports the other methods documented there as well, except that instead of taking a callback, the methods return a promise. E.g.:

client.bind('username', 'password').then(function () { ... });

The search method in ldapjs is now accessible (in promisified form) by client._search. I have provided a method client.search with similar behaviour as the original but an arguably easier API. E.g.:

client.search(base, options).then(function (result) {
  /* result is:
  {
    entries: [...],
    references: [...]
  }
  no messing about with EventEmitters!
  */
});

Let's face it, the reason why you're messing about with LDAP is probably to add LDAP authentication to your app, so I've added a couple of helper method for this:

client.authenticate(base, cn, password).then(function (result) {
  // if the authentication succeeded, then result is the LDAP user object
  // otherwise, it is null
});

This basically does a bind using the supplied credentials, and if successful, does a search for the specified user and returns that.

If all you really wanted was the user's name, email address, and list of unqualified groups, we can do that too:

client.authenticateUser(base, cn, password).then(function (result) {
  /*
  if the authentication succeeded, then result is:
  {
    name: <the user's DisplayName>,
    email: <the user's PrincipalName>,
    groups: <an array of the CNs of groups which are in the base CN>
  }
  otherwise, result is null
  */
});

Pull requests and suggestions are welcome!

promised-ldap's People

Watchers

 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.