New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.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.5.0 to 0.6.0

foo.js

2

CHANGES.md
## Changes
* v0.6.0
* Added option `credentialsLookup` that can be used eg. to add Basic Auth header parsing support.
* v0.5.0

@@ -4,0 +6,0 @@ * Updated deps. ldapauth-fork update changes bind credentials handling to work better with falsy values needed in anonymous bind.

@@ -133,4 +133,14 @@ "use strict";

username = lookup(req.body, this.options.usernameField) || lookup(req.query, this.options.usernameField);
password = lookup(req.body, this.options.passwordField) || lookup(req.query, this.options.passwordField);
if (typeof this.options.credentialsLookup === 'function') {
var credentials = this.options.credentialsLookup(req);
if (credentials != null) {
// name and pass as a courtesy for those who use basic-auth directly as
// they're likely the main user group.
username = credentials.username || credentials.name;
password = credentials.password || credentials.pass;
}
} else {
username = lookup(req.body, this.options.usernameField) || lookup(req.query, this.options.usernameField);
password = lookup(req.body, this.options.passwordField) || lookup(req.query, this.options.passwordField);
}

@@ -203,2 +213,3 @@ if (!username || !password) {

}
var callback = function(err, configuration) {

@@ -210,2 +221,3 @@ if (err) return this.fail(err);

};
// Added functionality: getOptions can accept now up to 2 parameters

@@ -212,0 +224,0 @@ if (this.getOptions.length ===1) { // Accepts 1 parameter, backwards compatibility

13

package.json

@@ -18,3 +18,3 @@ {

],
"version": "0.5.0",
"version": "0.6.0",
"license": "MIT",

@@ -37,9 +37,10 @@ "main": "./lib/passport-ldapauth",

"devDependencies": {
"body-parser": "1.14.x",
"chai": "3.4.x",
"express": "4.13.x",
"basic-auth": "1.0.x",
"body-parser": "1.15.x",
"chai": "3.5.x",
"express": "4.14.x",
"ldapjs": "1.0.x",
"mocha": "2.3.x",
"mocha": "3.0.x",
"passport": "0.3.x",
"supertest": "1.1.x"
"supertest": "2.0.x"
},

@@ -46,0 +47,0 @@ "scripts": {

@@ -45,2 +45,3 @@ # passport-ldapauth

* `passwordField`: Field name where the password is found, defaults to _password_
* `creadentialsLookup`: Optional, synchronous function that provides the login credentials from `req`. See [below](#credentials-lookup) for more.
* `passReqToCallback`: When `true`, `req` is the first argument to the verify callback (default: `false`):

@@ -136,3 +137,15 @@

```
<a name="credentials-lookup">
## `credentialsLookup`
A synchronous function that receives the `req` object and returns an objec with keys `username` and `password` (or `name` and `pass`) can be provided. Note, that when this is provided the default lookup is not performed. This can be used to eg. enable basic auth header support:
```javascript
var basicAuth = require('basic-auth');
var ldapOpts = {
server: { ... },
credentialsLookup: basicAuth
}
```
<a name="options-as-function"></a>

@@ -171,4 +184,20 @@ ## Asynchronous configuration retrieval

## `ldapsearch`
[ldapsearch](http://linux.die.net/man/1/ldapsearch) is a great command line tool for testing your config. The user search query performed in the Express example above when user logging in has uid `john` is the same as the following `ldapsearch` call:
```bash
ldapsearch \
-H ldap://localhost:389 \
-x \
-D cn=root \
-w secret \
-b ou=passport-ldapauth \
"(uid=john)"
```
If the query does not return expected user the configuration is likely incorrect.
## License
MIT
var should = require('chai').Should(),
LdapStrategy = require('passport-ldapauth'),
request = require('supertest'),
basicAuth = require('basic-auth'),
ldapserver = require('./ldapserver'),

@@ -211,2 +212,15 @@ appserver = require('./appserver');

});
it("should allow access with valid credentials in the header", function(cb) {
var OPTS = JSON.parse(JSON.stringify(BASE_OPTS));
OPTS.credentialsLookup = basicAuth;
start_servers(OPTS, BASE_TEST_OPTS)(function() {
request(expressapp)
.post('/login')
.set('Authorization', 'Basic dmFsaWQ6dmFsaWQ=')
.expect(200)
.end(cb);
});
});
});

@@ -301,11 +315,8 @@

describe("with group fetch settings defined", function() {
var OPTS = JSON.parse(JSON.stringify(BASE_OPTS));
OPTS.server.groupSearchBase = 'ou=passport-ldapauth';
OPTS.server.groupSearchScope = 'sub';
OPTS.server.groupSearchFilter = '(member={{dn}})';
var OPTS;
it("should return groups for user", function(cb) {
start_servers(OPTS, BASE_TEST_OPTS)(function() {
var groupTest = function(opts, cb) {
start_servers(opts, BASE_TEST_OPTS)(function() {
var req = {body: {username: 'valid', password: 'valid'}},
s = new LdapStrategy(OPTS, function(user, done) {
s = new LdapStrategy(opts, function(user, done) {
req.should.have.keys('body');

@@ -327,3 +338,24 @@ req.body.should.have.keys(['username', 'password']);

});
}
beforeEach(function(cb) {
OPTS = JSON.parse(JSON.stringify(BASE_OPTS));
OPTS.server.groupSearchBase = 'ou=passport-ldapauth';
OPTS.server.groupSearchScope = 'sub';
cb();
});
afterEach(stop_servers);
it("should return groups for user with string filter", function(cb) {
OPTS.server.groupSearchFilter = '(member={{dn}})';
groupTest(OPTS, cb);
});
it("should return groups for user with function filter", function(cb) {
OPTS.server.groupSearchFilter = function(user) {
return '(member={{dn}})'.replace(/{{dn}}/, user.dn)
};
groupTest(OPTS, cb);
});
});

@@ -330,0 +362,0 @@

Sorry, the diff of this file is not supported yet

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