mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-27 22:49:56 -05:00
29 lines
665 B
JavaScript
29 lines
665 B
JavaScript
|
const jwt = require('jsonwebtoken');
|
||
|
const common = require('../../../lib/common');
|
||
|
|
||
|
const authenticateMembersToken = (req, res, next) => {
|
||
|
if (!req.get('authorization')) {
|
||
|
return next();
|
||
|
}
|
||
|
|
||
|
const [scheme, credentials] = req.get('authorization').split(/\s+/);
|
||
|
|
||
|
if (scheme !== 'GhostMembers') {
|
||
|
return next();
|
||
|
}
|
||
|
|
||
|
return jwt.verify(credentials, null, {
|
||
|
algorithms: ['none']
|
||
|
}, function (err, claims) {
|
||
|
if (err) {
|
||
|
return next(new common.errors.UnauthorizedError({err}));
|
||
|
}
|
||
|
req.member = claims;
|
||
|
return next();
|
||
|
});
|
||
|
};
|
||
|
|
||
|
module.exports = {
|
||
|
authenticateMembersToken
|
||
|
};
|