From 6b2a3da7ee1aa34905886951d6df92e6b28814ba Mon Sep 17 00:00:00 2001 From: Jesse Hills <3060199+jesserockz@users.noreply.github.com> Date: Tue, 17 Dec 2024 17:35:15 +1300 Subject: [PATCH] Enhancement: support basic auth to ESPHome widget (#4429) --- docs/widgets/services/esphome.md | 3 ++- src/utils/proxy/handlers/credentialed.js | 4 +++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/docs/widgets/services/esphome.md b/docs/widgets/services/esphome.md index 07e511e37..e5dacb96a 100644 --- a/docs/widgets/services/esphome.md +++ b/docs/widgets/services/esphome.md @@ -16,5 +16,6 @@ To group both `offline` and `unknown` devices together, users should use the `of widget: type: esphome url: http://esphome.host.or.ip:port - key: myesphomecookie # only if auth enabled, get the value from a request from the frontend e.g. `authenticated=myesphomecookie` + username: myesphomeuser # only if auth enabled + password: myesphomepass # only if auth enabled ``` diff --git a/src/utils/proxy/handlers/credentialed.js b/src/utils/proxy/handlers/credentialed.js index cea95196a..01fb313b1 100644 --- a/src/utils/proxy/handlers/credentialed.js +++ b/src/utils/proxy/handlers/credentialed.js @@ -89,7 +89,9 @@ export default async function credentialedProxyHandler(req, res, map) { } else if (widget.type === "myspeed") { headers.Password = `${widget.password}`; } else if (widget.type === "esphome") { - if (widget.key) { + if (widget.username && widget.password) { + headers.Authorization = `Basic ${Buffer.from(`${widget.username}:${widget.password}`).toString("base64")}`; + } else if (widget.key) { headers.Cookie = `authenticated=${widget.key}`; } } else if (widget.type === "wgeasy") {