mirror of
https://github.com/n8n-io/n8n.git
synced 2024-11-16 01:24:05 -08:00
b03e358a12
* 👕 Enable `consistent-type-imports` for nodes-base
* 👕 Apply to nodes-base
* ⏪ Undo unrelated changes
* 🚚 Move to `.eslintrc.js` in nodes-base
* ⏪ Revert "Enable `consistent-type-imports` for nodes-base"
This reverts commit 529ad72b05
.
* 👕 Fix severity
60 lines
1.2 KiB
TypeScript
60 lines
1.2 KiB
TypeScript
import type {
|
|
ICredentialDataDecryptedObject,
|
|
ICredentialTestRequest,
|
|
ICredentialType,
|
|
IHttpRequestOptions,
|
|
INodeProperties,
|
|
} from 'n8n-workflow';
|
|
|
|
import jwt from 'jsonwebtoken';
|
|
export class GhostAdminApi implements ICredentialType {
|
|
name = 'ghostAdminApi';
|
|
|
|
displayName = 'Ghost Admin API';
|
|
|
|
documentationUrl = 'ghost';
|
|
|
|
properties: INodeProperties[] = [
|
|
{
|
|
displayName: 'URL',
|
|
name: 'url',
|
|
type: 'string',
|
|
default: '',
|
|
placeholder: 'http://localhost:3001',
|
|
},
|
|
{
|
|
displayName: 'API Key',
|
|
name: 'apiKey',
|
|
type: 'string',
|
|
typeOptions: { password: true },
|
|
default: '',
|
|
},
|
|
];
|
|
|
|
async authenticate(
|
|
credentials: ICredentialDataDecryptedObject,
|
|
requestOptions: IHttpRequestOptions,
|
|
): Promise<IHttpRequestOptions> {
|
|
const [id, secret] = (credentials.apiKey as string).split(':');
|
|
const token = jwt.sign({}, Buffer.from(secret, 'hex'), {
|
|
keyid: id,
|
|
algorithm: 'HS256',
|
|
expiresIn: '5m',
|
|
audience: '/v2/admin/',
|
|
});
|
|
|
|
requestOptions.headers = {
|
|
...requestOptions.headers,
|
|
Authorization: `Ghost ${token}`,
|
|
};
|
|
return requestOptions;
|
|
}
|
|
|
|
test: ICredentialTestRequest = {
|
|
request: {
|
|
baseURL: '={{$credentials.url}}',
|
|
url: '/ghost/api/v2/admin/pages/',
|
|
},
|
|
};
|
|
}
|