Skip to content

desouzas/passport-ldap-strat

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

passport-ldap-strat

This is a passport-strategy for LDAP authentication.

Build Status

Examples

Using with passport

import passport from 'passport';
import Strategy from 'passport-ldap-strat';
import express from 'express';
import bodyParser from 'body-parser';

let app = express();
// use body-parser to inflate json and x-www-form requests
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: true}));

// Build the strategy for localhost, with some basic search options to find
// groups that the user belongs to - after authenticating.
let strat = new Strategy({
	'server': {
		'url': 'ldap://localhost:8000'
	},
	'base': 'ou=people,dc=dev,ou=passport-ldap-strat',
	'uidTag': 'uid',
	'search': {
		'scope': 'sub',
		'base': 'ou=group,dc=dev,ou=passport-ldap-strat',
		'filter': '(memberuid=${uid})'
	},
	'usernameField': 'username',
	'passwordField': 'password'
}, (data, next) => {
	return next(null, data);
});

// use our strategy
passport.use(strat);

// init passport
app.use(passport.initialize());

// create an endpoint for POST /login
app.post('/login', (req, res) => {
	// try authenticate
	passport.authenticate('ldap', (err, searchRes, info) => {
		if (err) {
			// handle error
		}
		if (info) {
			// handle thrown error
		}
		// success
		// searchRes contains an array with the user's groups
	})(req, res);
});

Options

key type description
base string The suffix to use when binding.
passwordField string The request field to retrieve the password value from.
search object Contains the property filter - the search filter. The filter can contain a ${varName} variable and it will be replaced by the login username. scope and base may also be specified. See ldapjs docs for details.
server object Contains the property url - the ldap server url.
socketPath integer The ldap server port.
uidTag string The tag to use when binding the user (e.g. uid or cn).
usernameField string The request field to retrieve the username value from.

Running Tests

npm install
npm test

About

ldap strategy for passport

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published