From 2ff13a68425d6a9dd63eed908671568bbaa6cefa Mon Sep 17 00:00:00 2001 From: vcrwr <100850577+vcrwr@users.noreply.github.com> Date: Sun, 13 Mar 2022 11:49:15 +0100 Subject: [PATCH] feat(Hubspot): Add support for Private App Token Authentication --- .../credentials/HubspotAppToken.credentials.ts | 18 ++++++++++++++++++ .../nodes/Hubspot/GenericFunctions.ts | 6 ++++++ .../nodes-base/nodes/Hubspot/Hubspot.node.ts | 15 +++++++++++++++ packages/nodes-base/package.json | 1 + 4 files changed, 40 insertions(+) create mode 100644 packages/nodes-base/credentials/HubspotAppToken.credentials.ts diff --git a/packages/nodes-base/credentials/HubspotAppToken.credentials.ts b/packages/nodes-base/credentials/HubspotAppToken.credentials.ts new file mode 100644 index 0000000000..ab4f0a9503 --- /dev/null +++ b/packages/nodes-base/credentials/HubspotAppToken.credentials.ts @@ -0,0 +1,18 @@ +import { + ICredentialType, + INodeProperties, +} from 'n8n-workflow'; + +export class HubspotAppToken implements ICredentialType { + name = 'hubspotAppToken'; + displayName = 'Hubspot App Token'; + documentationUrl = 'hubspot'; + properties: INodeProperties[] = [ + { + displayName: 'App Token', + name: 'appToken', + type: 'string', + default: '', + }, + ]; +} diff --git a/packages/nodes-base/nodes/Hubspot/GenericFunctions.ts b/packages/nodes-base/nodes/Hubspot/GenericFunctions.ts index b390486b10..2a851a25b5 100644 --- a/packages/nodes-base/nodes/Hubspot/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Hubspot/GenericFunctions.ts @@ -27,6 +27,7 @@ export async function hubspotApiRequest(this: IHookFunctions | IExecuteFunctions const options: OptionsWithUri = { method, qs: query, + headers: {}, uri: uri || `https://api.hubapi.com${endpoint}`, body, json: true, @@ -39,6 +40,11 @@ export async function hubspotApiRequest(this: IHookFunctions | IExecuteFunctions options.qs.hapikey = credentials!.apiKey as string; return await this.helpers.request!(options); + } else if (authenticationMethod === 'appToken') { + const credentials = await this.getCredentials('hubspotAppToken'); + + options.headers!['Authorization'] = `Bearer ${credentials!.appToken}`; + return await this.helpers.request!(options); } else if (authenticationMethod === 'developerApi') { if (endpoint.includes('webhooks')) { diff --git a/packages/nodes-base/nodes/Hubspot/Hubspot.node.ts b/packages/nodes-base/nodes/Hubspot/Hubspot.node.ts index 298f6e7aaf..30926c6ee6 100644 --- a/packages/nodes-base/nodes/Hubspot/Hubspot.node.ts +++ b/packages/nodes-base/nodes/Hubspot/Hubspot.node.ts @@ -97,6 +97,17 @@ export class Hubspot implements INodeType { }, }, }, + { + name: 'hubspotAppToken', + required: true, + displayOptions: { + show: { + authentication: [ + 'appToken', + ], + }, + }, + }, { name: 'hubspotOAuth2Api', required: true, @@ -119,6 +130,10 @@ export class Hubspot implements INodeType { name: 'API Key', value: 'apiKey', }, + { + name: 'App Token', + value: 'appToken', + }, { name: 'OAuth2', value: 'oAuth2', diff --git a/packages/nodes-base/package.json b/packages/nodes-base/package.json index 973559d9c2..102a8ffdda 100644 --- a/packages/nodes-base/package.json +++ b/packages/nodes-base/package.json @@ -143,6 +143,7 @@ "dist/credentials/HttpHeaderAuth.credentials.js", "dist/credentials/HttpQueryAuth.credentials.js", "dist/credentials/HubspotApi.credentials.js", + "dist/credentials/HubspotAppToken.credentials.js", "dist/credentials/HubspotDeveloperApi.credentials.js", "dist/credentials/HubspotOAuth2Api.credentials.js", "dist/credentials/HumanticAiApi.credentials.js",