Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ var ldapOpts = {
## Asynchronous configuration retrieval

Instead of providing a static configuration object, you can pass a function as `options` that will take care of fetching the configuration. It will be called with the `req` object and a callback function having the standard `(err, result)` signature. Notice that the provided function will be called on every authenticate request.
If the function returns an error, the authentication request will error out with that error.

```javascript
var getLDAPConfiguration = function(req, callback) {
Expand Down
2 changes: 1 addition & 1 deletion lib/passport-ldapauth/strategy.js
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ Strategy.prototype.authenticate = function(req, options) {

var callback = function(err, configuration) {
if (err) {
return this.fail(err);
return this.error(err);
}

this.options = setDefaults(configuration);
Expand Down
19 changes: 19 additions & 0 deletions test/strategy-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,25 @@ describe('LDAP authentication strategy', function() {
});
});

describe('with options as function returning an error', function() {
var opts = function(cb) {
process.nextTick(function() {
cb(new Error('What a terrible failure'));
});
};

before(start_servers(opts, BASE_TEST_OPTS));
after(stop_servers);

it('should fail the authentication with an error', function(cb) {
request(expressapp)
.post('/login')
.send({username: 'valid', password: 'valid'})
.expect(500)
.end(cb);
});
});

describe('with group fetch settings defined', function() {
var OPTS;

Expand Down