Commit b49432d8 by tdgiang

Add Basic Auth middleware for the admin module

Co-Authored-By: 's avatarClaude Sonnet 5 <noreply@anthropic.com>
parent c98a2e9a
"use strict";
module.exports = function basicAuth(req, res, next) {
var config = require(__config_path + "/config");
var header = req.headers.authorization || "";
var token = header.indexOf("Basic ") === 0 ? header.slice(6) : "";
var decoded = Buffer.from(token, "base64").toString("utf8");
var parts = decoded.split(":");
var user = parts[0];
var password = parts[1];
if (user === config.admin.user && password === config.admin.password) {
return next();
}
res.set("WWW-Authenticate", 'Basic realm="Admin"');
return res.status(401).send("Authentication required.");
};
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