0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-01-27 22:49:56 -05:00
ghost/core/server/services/auth/members/index.js

29 lines
665 B
JavaScript
Raw Normal View History

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
};