mirror of
https://github.com/louislam/uptime-kuma.git
synced 2024-11-24 15:24:05 +00:00
Rename apiAuth
to basicAuthMiddleware
and it accepts API keys only
This commit is contained in:
parent
8dfe6c6ea9
commit
5773eeb6df
2 changed files with 10 additions and 24 deletions
|
@ -155,25 +155,11 @@ exports.basicAuth = async function (req, res, next) {
|
|||
* @param {express.NextFunction} next Next handler in chain
|
||||
* @returns {void}
|
||||
*/
|
||||
exports.apiAuth = async function (req, res, next) {
|
||||
if (!await Settings.get("disableAuth")) {
|
||||
let usingAPIKeys = await Settings.get("apiKeysEnabled");
|
||||
let middleware;
|
||||
if (usingAPIKeys) {
|
||||
middleware = basicAuth({
|
||||
exports.basicAuthMiddleware = async function (req, res, next) {
|
||||
let middleware = basicAuth({
|
||||
authorizer: apiAuthorizer,
|
||||
authorizeAsync: true,
|
||||
challenge: true,
|
||||
});
|
||||
} else {
|
||||
middleware = basicAuth({
|
||||
authorizer: userAuthorizer,
|
||||
authorizeAsync: true,
|
||||
challenge: true,
|
||||
});
|
||||
}
|
||||
middleware(req, res, next);
|
||||
} else {
|
||||
next();
|
||||
}
|
||||
};
|
||||
|
|
|
@ -97,7 +97,7 @@ log.debug("server", "Importing Background Jobs");
|
|||
const { initBackgroundJobs, stopBackgroundJobs } = require("./jobs");
|
||||
const { loginRateLimiter, twoFaRateLimiter } = require("./rate-limiter");
|
||||
|
||||
const { apiAuth } = require("./auth");
|
||||
const { basicAuthMiddleware } = require("./auth");
|
||||
const { login } = require("./auth");
|
||||
const passwordHash = require("./password-hash");
|
||||
|
||||
|
@ -267,8 +267,8 @@ let needSetup = false;
|
|||
// Basic Auth Router here
|
||||
|
||||
// Prometheus API metrics /metrics
|
||||
// With Basic Auth using the first user's username/password
|
||||
app.get("/metrics", apiAuth, prometheusAPIMetrics());
|
||||
// With Basic Auth using an API Key
|
||||
app.get("/metrics", basicAuthMiddleware, prometheusAPIMetrics());
|
||||
|
||||
app.use("/", expressStaticGzip("dist", {
|
||||
enableBrotli: true,
|
||||
|
|
Loading…
Reference in a new issue