I'm asking because it took me a long time to figure out how to fix it, I ended up with the following middleware to support basic authentication via LDAP:
const basicAuth = require('basic-auth');
const basicAuthenticator = (req, res, next) => {
function reject() {
res.statusCode = 401
res.setHeader('WWW-Authenticate', 'Basic realm="please use your SLO"')
res.end('Access denied')
}
var credentials = basicAuth(req)
if (!credentials) return reject();
ldap.authenticate(credentials.name, credentials.pass, function (err, user) {
if (err) return reject();
req.user = credentials.name;
next();
});
}
which I am not certain of, quite frankly, whether it handles all errors correctly.
connect no longer has a basicAuth method, because I believe they moved all middleware outside.
This mean that the example is broken.
Could it be fixed?
I'm asking because it took me a long time to figure out how to fix it, I ended up with the following middleware to support basic authentication via LDAP:
which I am not certain of, quite frankly, whether it handles all errors correctly.
Thank you!