From 2aa07a32e92e4c22f88ff36c93d0dc628bd6e9dc Mon Sep 17 00:00:00 2001 From: Koushik Dutta Date: Thu, 3 Nov 2022 09:11:07 -0700 Subject: [PATCH] server: add option to disable auth --- server/.vscode/launch.json | 1 + server/src/scrypted-server-main.ts | 15 +++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/server/.vscode/launch.json b/server/.vscode/launch.json index 39b7f5060..fd580a4ff 100644 --- a/server/.vscode/launch.json +++ b/server/.vscode/launch.json @@ -29,6 +29,7 @@ ], "env": { // "SCRYPTED_SHARED_WORKER": "true", + "SCRYPTED_DISABLE_AUTHENTICATION": "true", "DEBUG": "/scrypted/*", } }, diff --git a/server/src/scrypted-server-main.ts b/server/src/scrypted-server-main.ts index cbc1190e2..416d6fb22 100644 --- a/server/src/scrypted-server-main.ts +++ b/server/src/scrypted-server-main.ts @@ -179,6 +179,12 @@ async function start() { } app.use(async (req, res, next) => { + if (process.env.SCRYPTED_DISABLE_AUTHENTICATION === 'true') { + res.locals.username = 'anonymous'; + next(); + return; + } + // this is a trap for all auth. // only basic auth will fail with 401. it is up to the endpoints to manage // lack of login from cookie auth. @@ -538,6 +544,15 @@ async function start() { return; } + if (process.env.SCRYPTED_DISABLE_AUTHENTICATION === 'true') { + res.send({ + expiration: ONE_DAY_MILLISECONDS, + username: 'anonymous', + addresses, + }) + return; + } + try { const login_user_token = getSignedLoginUserTokenRawValue(req); if (!login_user_token)