Unverified Commit f4f032af authored by John McLear's avatar John McLear Committed by GitHub
Browse files

Merge pull request #3297 from apenwarr/auth-sequence

Call authentication hooks before default basic authentication.
parents 2765a957 e0582797
...@@ -36,13 +36,16 @@ exports.basicAuth = function (req, res, next) { ...@@ -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 (settings.users[username] != undefined && settings.users[username].password == password) { if (success) return cb(true);
settings.users[username].username = username; if (settings.users[username] != undefined && settings.users[username].password == password) {
req.session.user = settings.users[username]; settings.users[username].username = username;
return cb(true); req.session.user = settings.users[username];
} 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));
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment