From 7499e79dc75eae9691688d02534a574cfb2156dd Mon Sep 17 00:00:00 2001 From: Koushik Dutta Date: Fri, 19 Jul 2024 17:11:24 -0700 Subject: [PATCH] server: suppress WWW-authenticate --- server/src/scrypted-server-main.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/server/src/scrypted-server-main.ts b/server/src/scrypted-server-main.ts index f201ddc5d..fa10b42b4 100644 --- a/server/src/scrypted-server-main.ts +++ b/server/src/scrypted-server-main.ts @@ -161,6 +161,16 @@ async function start(mainFilename: string, options?: { callback(sha === user.passwordHash || password === user.token); }); + // the default http-auth will returns a WWW-Authenticate header if login fails. + // this causes the Safari to prompt for login. + // https://github.com/gevorg/http-auth/blob/4158fa75f58de70fd44aa68876a8674725e0556e/src/auth/base.js#L81 + // override the ask function to return a bare 401 instead. + // @ts-expect-error + basicAuth.ask = (res) => { + res.statusCode = 401; + res.end(); + }; + const httpsServerOptions = process.env.SCRYPTED_HTTPS_OPTIONS_FILE ? JSON.parse(fs.readFileSync(process.env.SCRYPTED_HTTPS_OPTIONS_FILE).toString()) : {};