mirror of
https://github.com/spacedeck/spacedeck-open.git
synced 2025-12-16 01:47:30 +01:00
allow auth via api_token
This commit is contained in:
@@ -4,6 +4,25 @@ const db = require('../models/db');
|
|||||||
var config = require('config');
|
var config = require('config');
|
||||||
|
|
||||||
module.exports = (req, res, next) => {
|
module.exports = (req, res, next) => {
|
||||||
|
|
||||||
|
// authentication via API token
|
||||||
|
const api_token = req.headers["x-spacedeck-api-token"];
|
||||||
|
|
||||||
|
if (api_token && api_token.length>7) {
|
||||||
|
db.User.findOne({where: {api_token: api_token}}).then(user => {
|
||||||
|
req.user = user;
|
||||||
|
next();
|
||||||
|
}).error(err => {
|
||||||
|
res.status(403).json({
|
||||||
|
"error": "invalid_api-token"
|
||||||
|
});
|
||||||
|
next();
|
||||||
|
});
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// authentication via session/cookie
|
||||||
const token = req.cookies["sdsession"];
|
const token = req.cookies["sdsession"];
|
||||||
|
|
||||||
if (token && token != "null" && token != null) {
|
if (token && token != "null" && token != null) {
|
||||||
@@ -44,4 +63,3 @@ module.exports = (req, res, next) => {
|
|||||||
next();
|
next();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user