Skip to content

Commit

Permalink
server: add query tokens to env auth
Browse files Browse the repository at this point in the history
  • Loading branch information
koush committed Mar 26, 2023
1 parent 2fd088e commit 0d03b91
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 15 deletions.
4 changes: 2 additions & 2 deletions server/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 17 additions & 13 deletions server/src/scrypted-server-main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -464,19 +464,6 @@ async function start(mainFilename: string, options?: {
res.send(200);
});

const resetLogin = path.join(getScryptedVolume(), 'reset-login');
async function checkResetLogin() {
try {
if (fs.existsSync(resetLogin)) {
fs.rmSync(resetLogin);
await db.removeAll(ScryptedUser);
hasLogin = false;
}
}
catch (e) {
}
}

app.post('/login', async (req, res) => {
const { username, password, change_password, maxAge: maxAgeRequested } = req.body;
const timestamp = Date.now();
Expand Down Expand Up @@ -562,6 +549,19 @@ async function start(mainFilename: string, options?: {
});
});

const resetLogin = path.join(getScryptedVolume(), 'reset-login');
async function checkResetLogin() {
try {
if (fs.existsSync(resetLogin)) {
fs.rmSync(resetLogin);
await db.removeAll(ScryptedUser);
hasLogin = false;
}
}
catch (e) {
}
}

app.get('/login', async (req, res) => {
await checkResetLogin();

Expand All @@ -570,7 +570,11 @@ async function start(mainFilename: string, options?: {

// env/header based admin login
if (res.locals.username && res.locals.username === process.env.SCRYPTED_ADMIN_USERNAME) {
const userToken = new UserToken(res.locals.username, undefined, Date.now());

res.send({
...createTokens(userToken),
expiration: ONE_DAY_MILLISECONDS,
username: res.locals.username,
token: process.env.SCRYPTED_ADMIN_TOKEN,
addresses,
Expand Down

0 comments on commit 0d03b91

Please sign in to comment.