mirror of
https://github.com/louislam/uptime-kuma.git
synced 2025-07-21 06:02:04 -04:00
Added API key authentication handler
API key authentication is now possible by making use of the X-API-Key header. API authentication will only be enabled when a user adds their first API key, up until this point, they can still use their username and password to authenticate with API endpoints. After the user adds their first API key, they may only use API keys in future to authenticate with the API. In this commit, the prometheus /metrics endpoint has been changed over to the new authentication system. Signed-off-by: Matthew Nickson <mnickson@sidingsmedia.com>
This commit is contained in:
parent
cd796898d0
commit
e7feca1cd6
3 changed files with 68 additions and 2 deletions
|
@ -5,6 +5,7 @@ const crypto = require("crypto");
|
|||
const passwordHash = require("../password-hash");
|
||||
const apicache = require("../modules/apicache");
|
||||
const APIKey = require("../model/api_key");
|
||||
const { Settings } = require("../settings");
|
||||
const { sendAPIKeyList } = require("../client");
|
||||
|
||||
/**
|
||||
|
@ -29,6 +30,10 @@ module.exports.apiKeySocketHandler = (socket) => {
|
|||
let formattedKey = bean.id + "-" + clearKey;
|
||||
await sendAPIKeyList(socket);
|
||||
|
||||
// Enable API auth if the user creates a key, otherwise only basic
|
||||
// auth will be used for API.
|
||||
await Settings.set("apiKeysEnabled", true);
|
||||
|
||||
callback({
|
||||
ok: true,
|
||||
msg: "Added Successfully.",
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue