🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

passport-ldapjs

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

passport-ldapjs

NodeJS Passport LDAP authentication using ldapjs

2.0.0
latest
Source
npm
Version published
Weekly downloads
8
-76.47%
Maintainers
1
Weekly downloads
 
Created
Source

passport-ldapjs

Passport strategy for authenticating against an LDAP server.

Tested with OpenLDAP server and Windows Server 2013 Active Directory

Install

$ npm install passport-ldapjs

Usage

Configure Strategy

The strategy requires a verify callback which accepts a user profile entry from the directory, and then calls the done callback supplying a user.

var LdapStrategy = require('passport-ldapjs').Strategy;

var opts = {
  server: {
    url: 'ldap://0.0.0.0:1389',
  },
  base: 'OU=Users,OU=Company,DC=company,DC=com',
  search: {
    filter: '(sAMAccountName={{username}})',
    attributes: ['displayName', 'givenName', 'mail', 'title', 'telephoneNumber', 'physiscalDeliveryOfficeName', 'userPrincipalName', 'sAMAccountName'],
    scope: 'sub'
  },
  uidTag: 'cn',
  usernameField: 'email',
  passwordField: 'passwd',
};

passport.use(new LdapStrategy(opts, function(profile, done) {
  User.findOne({email: email}, '-salt -password', function(err, user) {
    if (err) {
      return done(err);
    }

    if (user) {
      return done(null, user);
    } else {
      return done('User not found');
    }
  });
}));

Authenticate Requests

Use passport.authenticate(), specifying the 'ldap' strategy, to authenticate requests.

For example, as route middleware in an Express application:

// Create route
app.post('/login', passport.authenticate('ldap', {
  successReturnToOrRedirect: '/',
  failureRedirect: '/login',
  failureFlash: true
}));

Credits

  • Trinh Phuoc Thai

License

The MIT License

Copyright (c) 2015 Trinh Phuoc Thai <http://tphuocthai.com/>

Keywords

passport

FAQs

Package last updated on 12 Feb 2023

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