diff --git a/README.md b/README.md index c059463..669eec5 100644 --- a/README.md +++ b/README.md @@ -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) { diff --git a/lib/passport-ldapauth/strategy.js b/lib/passport-ldapauth/strategy.js index e3c9359..9b146bd 100644 --- a/lib/passport-ldapauth/strategy.js +++ b/lib/passport-ldapauth/strategy.js @@ -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); diff --git a/test/strategy-test.js b/test/strategy-test.js index 161264c..295b9c6 100644 --- a/test/strategy-test.js +++ b/test/strategy-test.js @@ -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;