From 578b715a1f8f5989e3703520e668e953472d8409 Mon Sep 17 00:00:00 2001 From: Ben Phelps Date: Fri, 16 Sep 2022 14:05:27 +0300 Subject: [PATCH] allow HTTP basic auth on generic proxy --- src/utils/proxies/generic.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/utils/proxies/generic.js b/src/utils/proxies/generic.js index 83dfeca1b..9e0a6a676 100644 --- a/src/utils/proxies/generic.js +++ b/src/utils/proxies/generic.js @@ -10,8 +10,17 @@ export default async function genericProxyHandler(req, res) { if (widget) { const url = new URL(formatApiCall(widget.type, { endpoint, ...widget })); + + let headers; + if (widget.username && widget.password) { + headers = { + Authorization: `Basic ${Buffer.from(`${widget.username}:${widget.password}`).toString("base64")}`, + }; + } + const [status, contentType, data] = await httpProxy(url, { method: req.method, + headers, }); if (contentType) res.setHeader("Content-Type", contentType);