2020-05-01 21:29:42 +03:00
|
|
|
const express = require('../../shared/express');
|
2021-06-30 16:56:57 +03:00
|
|
|
const settings = require('../../shared/settings-cache');
|
2020-01-20 14:45:58 +03:00
|
|
|
|
|
|
|
module.exports = function setupWellKnownApp() {
|
2020-05-01 21:29:42 +03:00
|
|
|
const wellKnownApp = express('well-known');
|
2020-01-20 14:45:58 +03:00
|
|
|
|
2021-10-21 11:27:56 +03:00
|
|
|
const jose = require('node-jose');
|
|
|
|
const dangerousPrivateKey = settings.get('ghost_private_key');
|
|
|
|
const keyStore = jose.JWK.createKeyStore();
|
|
|
|
const keyStoreReady = keyStore.add(dangerousPrivateKey, 'pem');
|
|
|
|
|
|
|
|
const getSafePublicJWKS = async () => {
|
|
|
|
await keyStoreReady;
|
|
|
|
return keyStore.toJSON();
|
|
|
|
};
|
|
|
|
|
2020-01-20 14:45:58 +03:00
|
|
|
wellKnownApp.get('/jwks.json', async (req, res) => {
|
|
|
|
const jwks = await getSafePublicJWKS();
|
|
|
|
res.json(jwks);
|
|
|
|
});
|
|
|
|
|
|
|
|
return wellKnownApp;
|
|
|
|
};
|