feat(ghost): add ghost integration (#1401)

This commit is contained in:
Rıdvan Akca
2023-11-07 13:30:26 +03:00
committed by GitHub
parent c42374e031
commit f0e8f070a8
11 changed files with 248 additions and 0 deletions

View File

@@ -0,0 +1,23 @@
import { TBeforeRequest } from '@automatisch/types';
import jwt from 'jsonwebtoken';
const addAuthHeader: TBeforeRequest = ($, requestConfig) => {
const key = $.auth.data?.apiKey as string;
if (key) {
const [id, secret] = key.split(':');
const token = jwt.sign({}, Buffer.from(secret, 'hex'), {
keyid: id,
algorithm: 'HS256',
expiresIn: '1h',
audience: `/admin/`,
});
requestConfig.headers.Authorization = `Ghost ${token}`;
}
return requestConfig;
};
export default addAuthHeader;

View File

@@ -0,0 +1,12 @@
import { TBeforeRequest } from '@automatisch/types';
const setBaseUrl: TBeforeRequest = ($, requestConfig) => {
const instanceUrl = $.auth.data.instanceUrl as string;
if (instanceUrl) {
requestConfig.baseURL = `${instanceUrl}/ghost/api`;
}
return requestConfig;
};
export default setBaseUrl;