Authenticate browser media with durable HttpOnly login cookies
Adapted cookie, origin, URL validation and secret handling from MikaelKW/nodecast-tv-plus. Protect API roles, revoke logins across restart, preserve existing accounts, and isolate transcode sessions by account. Co-authored-by: Mikael <mikaelkwessel@gmail.com>
This commit is contained in:
16
server/services/authTokens.js
Normal file
16
server/services/authTokens.js
Normal file
@ -0,0 +1,16 @@
|
||||
const { getDb } = require('../db/sqlite');
|
||||
|
||||
function store() {
|
||||
const db = getDb();
|
||||
db.exec('CREATE TABLE IF NOT EXISTS auth_revocations (id TEXT PRIMARY KEY, expires_at INTEGER NOT NULL)');
|
||||
db.exec('CREATE INDEX IF NOT EXISTS idx_auth_revocations_expiry ON auth_revocations(expires_at)');
|
||||
db.prepare('DELETE FROM auth_revocations WHERE expires_at <= ?').run(Math.floor(Date.now() / 1000));
|
||||
return db;
|
||||
}
|
||||
function isRevoked(payload) {
|
||||
return Boolean(store().prepare('SELECT 1 FROM auth_revocations WHERE id = ?').get(payload.jti));
|
||||
}
|
||||
function revoke(payload) {
|
||||
store().prepare('INSERT OR REPLACE INTO auth_revocations (id, expires_at) VALUES (?, ?)').run(payload.jti, payload.exp);
|
||||
}
|
||||
module.exports = { isRevoked, revoke };
|
||||
Reference in New Issue
Block a user