2021-07-19 15:02:45 +03:00
|
|
|
const errors = require('@tryghost/errors');
|
2021-12-02 17:46:58 +03:00
|
|
|
const logging = require('@tryghost/logging');
|
2021-07-19 15:02:45 +03:00
|
|
|
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
|
|
|
|
*/
|
|
|
|
|
|
|
|
module.exports = class WellKnownController {
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @param {object} deps
|
2021-12-02 17:46:58 +03:00
|
|
|
* @param {ITokenService} deps.tokenService
|
2021-07-19 15:02:45 +03:00
|
|
|
*/
|
|
|
|
constructor(deps) {
|
|
|
|
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
|
|
|
|
});
|
2021-12-02 17:46:58 +03:00
|
|
|
logging.error(error);
|
2021-07-19 15:02:45 +03:00
|
|
|
throw error;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|