Ghost/core/server/services/auth/members/index.js
Fabien O'Carroll 48923ac327
Wired members service up to api and app (#10262)
* Updated auth service members middleware

refs #10213

* Wired up members api router to the ghost api endpoints

refs #10213

* Created members app for the static pages

refs #10213

* Wired up the members app

refs #10213
2018-12-11 15:18:07 +07:00

41 lines
1.2 KiB
JavaScript

const jwt = require('express-jwt');
const membersService = require('../../members');
const labs = require('../../labs');
const config = require('../../../config');
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: config.get('url'),
issuer: config.get('url'),
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;
}
};