verdaccio-ldap-node
Advanced tools
Comparing version 1.0.0 to 1.0.1
69
index.js
/** | ||
* verdaccio-ldap | ||
* verdaccio-ldap-node | ||
*/ | ||
'use strict'; | ||
'use strict'; | ||
const LdapClient = require('node-ldap'); | ||
function Auth(config, stuff) { | ||
const self = Object.create(Auth.prototype); | ||
self._users = {}; | ||
// config for this module | ||
self._config = config; | ||
// verdaccio logger | ||
self._logger = stuff.logger; | ||
// pass verdaccio logger to ldapauth | ||
self._config.client_options.log = stuff.logger; | ||
// initial ldapUrl | ||
self._config.client_options.ldapUrl = ''; | ||
return self; | ||
} | ||
Auth.prototype.authenticate = function(username, password, callback) { | ||
// initial LDAP client | ||
const client = new LdapClient(this._config.client_options); | ||
// start auth | ||
client.auth(`${username}@xdf.cn`, password) | ||
.then(function() { | ||
callback(null, [ username ]); | ||
}) | ||
.catch(function(error) { | ||
this._logger.warn({ username, error }, `verdaccio-ldap error ${error}`); | ||
callback(null, false); | ||
}) | ||
.finally(function() { | ||
client.disconnect(); | ||
}); | ||
}; | ||
module.exports = Auth; | ||
const LdapClient = require('node-ldap'); | ||
function Auth(config, stuff) { | ||
const self = Object.create(Auth.prototype); | ||
self._users = {}; | ||
// config for this module | ||
self._config = config; | ||
// verdaccio logger | ||
self._logger = stuff.logger; | ||
return self; | ||
} | ||
Auth.prototype.authenticate = function(username, password, callback) { | ||
// initial LDAP client | ||
const client = new LdapClient(this._config); | ||
// start auth | ||
client.auth(`${username}@xdf.cn`, password) | ||
.then(function() { | ||
callback(null, [ username ]); | ||
}) | ||
.catch(function(error) { | ||
this._logger.warn({ username, error }, `verdaccio-ldap error ${error}`); | ||
callback(null, false); | ||
}) | ||
.finally(function() { | ||
client.disconnect(); | ||
}); | ||
}; | ||
module.exports = Auth; | ||
{ | ||
"name": "verdaccio-ldap-node", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "LDAP plugin for Verdaccio with node-ldap", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
2320
31