mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-22 02:11:44 +03:00
48923ac327
* 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
41 lines
1.2 KiB
JavaScript
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;
|
|
}
|
|
};
|