Merge pull request #3297 from apenwarr/auth-sequence

Call authentication hooks before default basic authentication.
pull/3164/head^2
John McLear 2018-04-03 13:41:51 +01:00 committed by GitHub
commit f4f032afc0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 10 additions and 7 deletions

View File

@ -36,13 +36,16 @@ exports.basicAuth = function (req, res, next) {
var userpass = new Buffer(req.headers.authorization.split(' ')[1], 'base64').toString().split(":") var userpass = new Buffer(req.headers.authorization.split(' ')[1], 'base64').toString().split(":")
var username = userpass.shift(); var username = userpass.shift();
var password = userpass.join(':'); var password = userpass.join(':');
var fallback = function(success) {
if (success) return cb(true);
if (settings.users[username] != undefined && settings.users[username].password == password) { if (settings.users[username] != undefined && settings.users[username].password == password) {
settings.users[username].username = username; settings.users[username].username = username;
req.session.user = settings.users[username]; req.session.user = settings.users[username];
return cb(true); return cb(true);
} }
return hooks.aCallFirst("authenticate", {req: req, res:res, next:next, username: username, password: password}, hookResultMangle(cb)); return cb(false);
};
return hooks.aCallFirst("authenticate", {req: req, res:res, next:next, username: username, password: password}, hookResultMangle(fallback));
} }
hooks.aCallFirst("authenticate", {req: req, res:res, next:next}, hookResultMangle(cb)); hooks.aCallFirst("authenticate", {req: req, res:res, next:next}, hookResultMangle(cb));
} }