diff --git a/index.js b/index.js index eb15c15..84285c6 100644 --- a/index.js +++ b/index.js @@ -16,7 +16,6 @@ module.exports = function(plugin) { } }); - var client = ldap.createClient(plugin.conf.options) function requestAuth(res) { res.set('WWW-Authenticate', 'Basic realm="Auth"'); @@ -41,6 +40,9 @@ module.exports = function(plugin) { return; } + // It seems stupid to create a client each time, but joyent's ldapjs cannot bind then unbind to the same client multiple times... + var client = ldap.createClient(plugin.conf.options) + client.bind(plugin.conf.bind.dn.replace('%u', login), plugin.conf.bind.password.replace('%p', password), function(err) { if (err) { console.log('E: ldap.bind: ', err) @@ -51,8 +53,8 @@ module.exports = function(plugin) { if (err) { console.log('E: ldap.unbind: ', err) } - next(); }) + next(); } }) });