mirror of
https://gitlab.com/wgp/dougal/software.git
synced 2025-12-06 13:07:08 +00:00
28 lines
639 B
JavaScript
28 lines
639 B
JavaScript
const {expressjwt: expressJWT} = require('express-jwt');
|
|
|
|
const cfg = require("../../../lib/config").jwt;
|
|
|
|
const getToken = function (req) {
|
|
if (req.headers.authorization && req.headers.authorization.split(' ')[0] == 'Bearer') {
|
|
return req.headers.authorization.split(' ')[1];
|
|
} else if (req.cookies.JWT) {
|
|
return req.cookies.JWT;
|
|
}
|
|
return null;
|
|
}
|
|
|
|
const options = {
|
|
secret: cfg.secret,
|
|
credentialsRequired: false,
|
|
algorithms: ['HS256'],
|
|
requestProperty: "user",
|
|
getToken
|
|
};
|
|
|
|
const allow = {
|
|
path: [/\/login$/, /\/logout$/, /\/$/, /\/version$/],
|
|
useOriginalUrl: false
|
|
};
|
|
|
|
module.exports = expressJWT(options).unless(allow);
|