feat(Hubspot): Add support for Private App Token Authentication

This commit is contained in:
vcrwr 2022-03-13 11:49:15 +01:00 committed by GitHub
parent 4d4db7f805
commit 2ff13a6842
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 40 additions and 0 deletions

View file

@ -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: '',
},
];
}

View file

@ -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')) {

View file

@ -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',

View file

@ -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",