Skip to content

Commit

Permalink
Enhancement: support basic auth to ESPHome widget (#4429)
Browse files Browse the repository at this point in the history
  • Loading branch information
jesserockz authored Dec 17, 2024
1 parent b853c56 commit 6b2a3da
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
3 changes: 2 additions & 1 deletion docs/widgets/services/esphome.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
4 changes: 3 additions & 1 deletion src/utils/proxy/handlers/credentialed.js
Original file line number Diff line number Diff line change
Expand Up @@ -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") {
Expand Down

0 comments on commit 6b2a3da

Please sign in to comment.