feat(ghost): add ghost integration (#1401)
This commit is contained in:
23
packages/backend/src/apps/ghost/common/add-auth-header.ts
Normal file
23
packages/backend/src/apps/ghost/common/add-auth-header.ts
Normal 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;
|
12
packages/backend/src/apps/ghost/common/set-base-url.ts
Normal file
12
packages/backend/src/apps/ghost/common/set-base-url.ts
Normal 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;
|
Reference in New Issue
Block a user