From 5ea4dc03b85c81a4ef11b722cf3abfd6ebab84a7 Mon Sep 17 00:00:00 2001 From: Harshil Agrawal Date: Sat, 18 Sep 2021 22:18:35 +0200 Subject: [PATCH] :zap: Add OAuth to HubSpot Trigger node credentials (#2166) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 🔨 HubSpot Trigger node credentials * :zap: Small changes * :zap: Add breaking change message Co-authored-by: ricardo --- packages/cli/BREAKING-CHANGES.md | 14 ++++++ .../HubspotDeveloperApi.credentials.ts | 50 ++++++++++++++++--- .../nodes/Hubspot/HubspotTrigger.node.ts | 14 ++---- 3 files changed, 61 insertions(+), 17 deletions(-) diff --git a/packages/cli/BREAKING-CHANGES.md b/packages/cli/BREAKING-CHANGES.md index 03f23cab4d..774d9705eb 100644 --- a/packages/cli/BREAKING-CHANGES.md +++ b/packages/cli/BREAKING-CHANGES.md @@ -2,6 +2,20 @@ This list shows all the versions which include breaking changes and how to upgrade. +## 0.139.0 + +### What changed? + +For the HubSpot Trigger node, the authentication process has changed to OAuth2. + +### When is action necessary? + +If you are using the Hubspot Trigger. + +### How to upgrade: + +Create an app in HubSpot, use the Client ID, Client Secret, App ID, and the Developer Key, and complete the OAuth2 flow. + ## 0.135.0 ### What changed? diff --git a/packages/nodes-base/credentials/HubspotDeveloperApi.credentials.ts b/packages/nodes-base/credentials/HubspotDeveloperApi.credentials.ts index dc808767c9..0de15fe956 100644 --- a/packages/nodes-base/credentials/HubspotDeveloperApi.credentials.ts +++ b/packages/nodes-base/credentials/HubspotDeveloperApi.credentials.ts @@ -3,11 +3,45 @@ import { INodeProperties, } from 'n8n-workflow'; +const scopes = [ + 'contacts', +]; + export class HubspotDeveloperApi implements ICredentialType { name = 'hubspotDeveloperApi'; displayName = 'Hubspot Developer API'; documentationUrl = 'hubspot'; + extends = [ + 'oAuth2Api', + ]; properties: INodeProperties[] = [ + { + displayName: 'Authorization URL', + name: 'authUrl', + type: 'hidden', + default: 'https://app.hubspot.com/oauth/authorize', + required: true, + }, + { + displayName: 'Access Token URL', + name: 'accessTokenUrl', + type: 'hidden', + default: 'https://api.hubapi.com/oauth/v1/token', + required: true, + }, + { + displayName: 'Auth URI Query Parameters', + name: 'authQueryParameters', + type: 'hidden', + default: 'grant_type=authorization_code', + }, + { + displayName: 'Authentication', + name: 'authentication', + type: 'hidden', + default: 'body', + description: 'Resource to consume.', + }, { displayName: 'Developer API Key', name: 'apiKey', @@ -15,18 +49,18 @@ export class HubspotDeveloperApi implements ICredentialType { default: '', }, { - displayName: 'Client Secret', - name: 'clientSecret', - type: 'string', - default: '', - }, - { - displayName: 'App ID', + displayName: 'APP ID', name: 'appId', type: 'string', required: true, default: '', - description: 'The App ID', + description: 'The APP ID', + }, + { + displayName: 'Scope', + name: 'scope', + type: 'hidden', + default: scopes.join(' '), }, ]; } diff --git a/packages/nodes-base/nodes/Hubspot/HubspotTrigger.node.ts b/packages/nodes-base/nodes/Hubspot/HubspotTrigger.node.ts index 0551d9b184..fce1e0e40a 100644 --- a/packages/nodes-base/nodes/Hubspot/HubspotTrigger.node.ts +++ b/packages/nodes-base/nodes/Hubspot/HubspotTrigger.node.ts @@ -370,15 +370,11 @@ export class HubspotTrigger implements INodeType { return {}; } - // check signare if client secret is defined - - if (credentials.clientSecret !== '') { - const hash = `${credentials!.clientSecret}${JSON.stringify(bodyData)}`; - const signature = createHash('sha256').update(hash).digest('hex'); - //@ts-ignore - if (signature !== headerData['x-hubspot-signature']) { - return {}; - } + const hash = `${credentials!.clientSecret}${JSON.stringify(bodyData)}`; + const signature = createHash('sha256').update(hash).digest('hex'); + //@ts-ignore + if (signature !== headerData['x-hubspot-signature']) { + return {}; } for (let i = 0; i < bodyData.length; i++) {