|
|
@ -31,10 +31,6 @@ exports.login = async function (username, password) {
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
function myAuthorizer(username, password, callback) {
|
|
|
|
function myAuthorizer(username, password, callback) {
|
|
|
|
setting("disableAuth").then((result) => {
|
|
|
|
|
|
|
|
if (result) {
|
|
|
|
|
|
|
|
callback(null, true);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
// Login Rate Limit
|
|
|
|
// Login Rate Limit
|
|
|
|
loginRateLimiter.pass(null, 0).then((pass) => {
|
|
|
|
loginRateLimiter.pass(null, 0).then((pass) => {
|
|
|
|
if (pass) {
|
|
|
|
if (pass) {
|
|
|
@ -49,13 +45,27 @@ function myAuthorizer(username, password, callback) {
|
|
|
|
callback(null, false);
|
|
|
|
callback(null, false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
exports.basicAuth = basicAuth({
|
|
|
|
/**
|
|
|
|
|
|
|
|
* If disabled auth, it does not call `next`.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
exports.checkBasicAuth = async (req, res, next) => {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
exports.basicAuth = async function (req, res, next) {
|
|
|
|
|
|
|
|
const middleware = basicAuth({
|
|
|
|
authorizer: myAuthorizer,
|
|
|
|
authorizer: myAuthorizer,
|
|
|
|
authorizeAsync: true,
|
|
|
|
authorizeAsync: true,
|
|
|
|
challenge: true,
|
|
|
|
challenge: true,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const disabledAuth = await setting("disableAuth");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!disabledAuth) {
|
|
|
|
|
|
|
|
middleware(req, res, next);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
next();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|