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

44 lines
1.2 KiB
JavaScript
Raw Normal View History

const URL = require('url').URL;
const jwt = require('express-jwt');
const membersService = require('../../members');
const labs = require('../../labs');
const config = require('../../../config');
const siteOrigin = new URL(config.get('url')).origin;
let UNO_MEMBERINO;
module.exports = {
get authenticateMembersToken() {
if (!labs.isSet('members')) {
return function (req, res, next) {
return next();
};
}
if (!UNO_MEMBERINO) {
UNO_MEMBERINO = jwt({
credentialsRequired: false,
requestProperty: 'member',
audience: siteOrigin,
issuer: siteOrigin,
algorithm: 'RS512',
secret: membersService.api.publicKey,
getToken(req) {
if (!req.get('authorization')) {
return null;
}
const [scheme, credentials] = req.get('authorization').split(/\s+/);
if (scheme !== 'GhostMembers') {
return null;
}
return credentials;
}
});
}
return UNO_MEMBERINO;
}
};