mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-21 09:52:06 +03:00
caf059cd7e
refs https://github.com/TryGhost/Team/issues/664 The well known controller is designed to handle any requests to the /.well-known endpoint where the members app is mounted. The first and only requirement so far is that we expose a JSON Web Key Set so that external services are able to validate Members JWT's
55 lines
1.3 KiB
JavaScript
55 lines
1.3 KiB
JavaScript
const errors = require('@tryghost/errors');
|
|
const tpl = require('@tryghost/tpl');
|
|
|
|
const messages = {
|
|
keyStoreError: 'There was an error with the keystore. Please check the settings.'
|
|
};
|
|
|
|
/**
|
|
* @typedef {import('node-jose').JWK[]} JWKS
|
|
*/
|
|
|
|
/**
|
|
* @typedef {object} ITokenService
|
|
* @prop {() => Promise<JWKS>} getPublicKeys
|
|
*/
|
|
|
|
/**
|
|
* @typedef {object} ILogging
|
|
* @prop {(msg) => void} info
|
|
* @prop {(msg) => void} warn
|
|
* @prop {(msg) => void} error
|
|
*/
|
|
|
|
module.exports = class WellKnownController {
|
|
/**
|
|
*
|
|
* @param {object} deps
|
|
* @param {ITokenService} deps.tokenService
|
|
* @param {ILogging} deps.logging
|
|
*/
|
|
constructor(deps) {
|
|
this._logging = deps.logging;
|
|
this._tokenService = deps.tokenService;
|
|
}
|
|
|
|
/**
|
|
*
|
|
* @param {import('express').Request} req
|
|
* @param {import('express').Response} res
|
|
*/
|
|
async getPublicKeys(req, res) {
|
|
try {
|
|
const jwks = await this._tokenService.getPublicKeys();
|
|
res.json(jwks);
|
|
} catch (err) {
|
|
const error = new errors.InternalServerError({
|
|
message: tpl(messages.keyStoreError),
|
|
err
|
|
});
|
|
this._logging.error(error);
|
|
throw error;
|
|
}
|
|
}
|
|
};
|