Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

passport-ldapauth

Package Overview
Dependencies
Maintainers
1
Versions
31
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

passport-ldapauth - npm Package Compare versions

Comparing version 0.2.1 to 0.2.2

TODO.md

5

CHANGES.md
## Changes
* v0.2.2
* Allow configuring flash messages when calling `passport.authenticate()`
* Return HTTP 400 when username or password is missing
* v0.2.1
* Passport as peerDependency, prevents version incompatibility
* v0.2.0

@@ -4,0 +9,0 @@ * [#8](https://github.com/vesse/passport-ldapauth/issues/8) - Possibility to provide a callback function instead of options object to constructor (contributed by Linagora)

18

lib/passport-ldapauth/strategy.js

@@ -117,2 +117,12 @@ "use strict";

/**
* Options (passed when calling `passport.authenticate()`):
* - `badRequestMessage` flash message for missing username/password
* (default: 'Missing credentials')
* - `invalidCredentials` flash message for InvalidCredentialsError, NoSuchObjectError,
* and /no such user/ LDAP errors
* (default: 'Invalid username/password')
* - `userNotFound` flash message when LDAP returns no error but also no user
* (default: 'Invalid username/password')
*/
var handleAuthentication = function(req, options) {

@@ -125,3 +135,5 @@ var username, password, ldap;

if (!username || !password) return this.fail('Missing credentials');
if (!username || !password) {
return this.fail({message: options.badRequestMessage || 'Missing credentials'}, 400);
}

@@ -134,3 +146,3 @@ ldap = new LdapAuth(this.options.server);

if (err.name === 'InvalidCredentialsError' || err.name === 'NoSuchObjectError' || (typeof err === 'string' && err.match(/no such user/i))) {
return this.fail('Invalid username/password');
return this.fail({message: options.invalidCredentials || 'Invalid username/password'}, 401);
}

@@ -141,3 +153,3 @@ // Other errors are (most likely) real errors

if (!user) return this.fail('User not found');
if (!user) return this.fail({message: options.userNotFound || 'Invalid username/password'}, 401);

@@ -144,0 +156,0 @@ // Execute given verify function

10

package.json

@@ -15,3 +15,3 @@ {

],
"version": "0.2.1",
"version": "0.2.2",
"license": {

@@ -39,8 +39,8 @@ "type": "MIT",

"devDependencies": {
"body-parser": "1.3.x",
"body-parser": "1.9.x",
"chai": "1.9.x",
"express": "4.4.x",
"express": "4.9.x",
"ldapjs": "0.7.x",
"mocha": "1.20.x",
"supertest": "0.13.x",
"mocha": "1.21.x",
"supertest": "0.14.x",
"passport": "~0.2.0"

@@ -47,0 +47,0 @@ },

@@ -5,17 +5,17 @@ # passport-ldapauth

## Usage
## Install
```javascript
var LdapStrategy = require('passport-ldapauth').Strategy;
passport.use(new LdapStrategy({
server: {
url: 'ldap://localhost:389',
...
}
}));
```
npm install passport-ldapauth
```
If you wish to e.g. do some additional verification or initialize user data to local database you may supply a `verify` callback which accepts `user` object and then calls the `done` callback supplying a `user`, which should be set to `false` if user is not allowed to authenticate. If an exception occured, `err` should be set.
## Status
[![Build Status](https://travis-ci.org/vesse/passport-ldapauth.png)](https://travis-ci.org/vesse/passport-ldapauth)
[![Dependency Status](https://gemnasium.com/vesse/passport-ldapauth.png)](https://gemnasium.com/vesse/passport-ldapauth)
## Usage
### Configure strategy
```javascript

@@ -29,23 +29,5 @@ var LdapStrategy = require('passport-ldapauth').Strategy;

}
},
function(user, done) {
...
return done(null, user);
}
));
}));
```
## Install
```
npm install passport-ldapauth
```
## Status
[![Build Status](https://travis-ci.org/vesse/passport-ldapauth.png)](https://travis-ci.org/vesse/passport-ldapauth)
[![Dependency Status](https://gemnasium.com/vesse/passport-ldapauth.png)](https://gemnasium.com/vesse/passport-ldapauth)
## Configuration options
* `server`: LDAP settings. These are passed directly to [ldapauth-fork](https://github.com/vesse/node-ldapauth-fork). See its documentation for all available options.

@@ -71,2 +53,14 @@ * `url`: e.g. `ldap://localhost:389`

### Authenticate requests
Use `passport.authenticate()`, specifying the `'ldapauth'` strategy, to authenticate requests.
#### `authenticate()` options
In addition to [default authentication options](http://passportjs.org/guide/authenticate/) the following options are available for `passport.authenticate()`:
* `badRequestMessage` flash message for missing username/password (default: 'Missing credentials')
* `invalidCredentials` flash message for `InvalidCredentialsError`, `NoSuchObjectError`, and `/no such user/i` LDAP errors (default: 'Invalid username/password')
* `userNotFound` flash message when LDAP returns no error but also no user (default: 'Invalid username/password')
## Express example

@@ -73,0 +67,0 @@

@@ -13,2 +13,3 @@ var express = require('express'),

searchFilter: '(uid={{username}})',
cache: false,
log4js: log4js

@@ -21,5 +22,2 @@ }

passport.serializeUser(function(user, done) {
console.log('user : ' + user);
console.log('done : ' + done);
console.log('serializeUser was called');
done(null, 1);

@@ -29,3 +27,2 @@ });

passport.deserializeUser(function(obj, done) {
console.log('deserializeUser was called');
done(null, obj);

@@ -48,3 +45,3 @@ });

app.all('*', function(req, res, next) {
console.log('Request', req.headers, req.body);
console.log('Request');
next();

@@ -51,0 +48,0 @@ });

@@ -24,3 +24,3 @@ var express = require('express'),

app.use(bodyParser());
app.use(bodyParser.json());
app.use(passport.initialize());

@@ -27,0 +27,0 @@

@@ -82,3 +82,3 @@ var should = require('chai').Should(),

.send({})
.expect(401)
.expect(400)
.end(cb);

@@ -208,3 +208,3 @@ });

.send({username: 'valid', password: 'valid'})
.expect(401)
.expect(400)
.end(cb);

@@ -211,0 +211,0 @@ });

Sorry, the diff of this file is not supported yet

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