Switch to joyent's ldapjs lib

This commit is contained in:
Ketchetwahmeegwun T. Southall 2020-07-10 18:51:45 -07:00
parent c145bfd198
commit 1095d80a34
3 changed files with 54 additions and 22 deletions

View File

@ -1,4 +1,4 @@
var LdapClient = require('ldapjs-client');
var ldap = require('ldapjs');
var session = require('express-session');
var router = module.parent.router;
@ -16,7 +16,7 @@ module.exports = function(plugin) {
}
});
var ldap = new LdapClient(plugin.conf.options)
var client = ldap.createClient(plugin.conf.options)
function requestAuth(res) {
res.set('WWW-Authenticate', 'Basic realm="Auth"');
@ -41,18 +41,19 @@ module.exports = function(plugin) {
return;
}
ldap.bind(plugin.conf.bind.dn.replace('%u', login), plugin.conf.bind.password.replace('%p', password))
.then(function() {
req.session.isValid = true;
ldap.unbind(function(err) {
console.log('E: ldap.unbind: ', err)
})
next();
})
.catch(function(err) {
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)
requestAuth(res);
} else {
req.session.isValid = true;
client.unbind(function(err) {
if (err) {
console.log('E: ldap.unbind: ', err)
}
next();
})
}
})
});
};

45
package-lock.json generated
View File

@ -1,6 +1,6 @@
{
"name": "ngwiki-plugin-auth-ldap",
"version": "1.0.0",
"version": "2.0.0",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
@ -9,6 +9,11 @@
"resolved": "https://registry.npmjs.org/abbrev/-/abbrev-1.1.1.tgz",
"integrity": "sha1-+PLIh60Qv2f2NPAFtph/7TF5qsg="
},
"abstract-logging": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/abstract-logging/-/abstract-logging-1.0.0.tgz",
"integrity": "sha1-i33q/TEFWbwo93ck3RuzAXcnjBs="
},
"ajv": {
"version": "6.7.0",
"resolved": "https://registry.npmjs.org/ajv/-/ajv-6.7.0.tgz",
@ -67,6 +72,14 @@
"resolved": "https://registry.npmjs.org/aws4/-/aws4-1.8.0.tgz",
"integrity": "sha1-8OAD2cqef1nHpQiUXXsu+aBKVC8="
},
"backoff": {
"version": "2.5.0",
"resolved": "https://registry.npmjs.org/backoff/-/backoff-2.5.0.tgz",
"integrity": "sha1-9hbtqdPktmuMp/ynn2lXIsX44m8=",
"requires": {
"precond": "0.2"
}
},
"balanced-match": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz",
@ -403,14 +416,19 @@
"assert-plus": "^1.0.0"
}
},
"ldapjs-client": {
"version": "0.1.1",
"resolved": "https://registry.npmjs.org/ldapjs-client/-/ldapjs-client-0.1.1.tgz",
"integrity": "sha512-N2vh1Qc0h7tsc+FSJRcVgeVyoiCS4IOm7XG5lBWfb2ZbMr7bH+DCgEF/K72EY0/WTd8amHBj5CDjYz5Y//0J1w==",
"ldapjs": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/ldapjs/-/ldapjs-2.0.0.tgz",
"integrity": "sha512-ZESQmVoG4a2ZX51pl/aRI+/kqiN2eRWMgHIsNZ2TYf37/S64OPnVJL5Vd5gdZR/qRPZVe5uuKW5p0GK2FUx/FQ==",
"requires": {
"asn1": "0.2.4",
"abstract-logging": "^1.0.0",
"asn1": "^0.2.4",
"assert-plus": "^1.0.0",
"ldap-filter": "0.3.3"
"backoff": "^2.5.0",
"ldap-filter": "^0.3.3",
"once": "^1.4.0",
"vasync": "^2.2.0",
"verror": "^1.8.1"
}
},
"mime-db": {
@ -552,6 +570,11 @@
"resolved": "https://registry.npmjs.org/performance-now/-/performance-now-2.1.0.tgz",
"integrity": "sha1-Ywn04OX6kT7BxpMHrjZLSzd8nns="
},
"precond": {
"version": "0.2.3",
"resolved": "https://registry.npmjs.org/precond/-/precond-0.2.3.tgz",
"integrity": "sha1-qpWRvKokkj8eD0hJ0kD0fvwQdaw="
},
"process-nextick-args": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/process-nextick-args/-/process-nextick-args-2.0.0.tgz",
@ -763,6 +786,14 @@
"resolved": "https://registry.npmjs.org/uuid/-/uuid-3.3.2.tgz",
"integrity": "sha1-G0r0lV6zB3xQHCOHL8ZROBFYcTE="
},
"vasync": {
"version": "2.2.0",
"resolved": "https://registry.npmjs.org/vasync/-/vasync-2.2.0.tgz",
"integrity": "sha1-z951GGChWCLbOxMrxZsRakra8Bs=",
"requires": {
"verror": "1.10.0"
}
},
"verror": {
"version": "1.10.0",
"resolved": "https://registry.npmjs.org/verror/-/verror-1.10.0.tgz",

View File

@ -10,7 +10,7 @@
"license": "GPL-3.0",
"dependencies": {
"express-session": "^1.15.6",
"ldapjs-client": "^0.1.1",
"ldapjs": "^2.0.0",
"node-gyp": "^3.8.0"
}
}