mirror of
https://github.com/n8n-io/n8n.git
synced 2025-01-12 05:17:28 -08:00
Merge pull request #673 from n8n-io/AcuityScheduling-OAuth2-support
Acuity scheduling OAuth2 support
This commit is contained in:
commit
e03a937888
|
@ -0,0 +1,48 @@
|
|||
import {
|
||||
ICredentialType,
|
||||
NodePropertyTypes,
|
||||
} from 'n8n-workflow';
|
||||
|
||||
|
||||
export class AcuitySchedulingOAuth2Api implements ICredentialType {
|
||||
name = 'acuitySchedulingOAuth2Api';
|
||||
extends = [
|
||||
'oAuth2Api',
|
||||
];
|
||||
displayName = 'AcuityScheduling OAuth2 API';
|
||||
properties = [
|
||||
{
|
||||
displayName: 'Authorization URL',
|
||||
name: 'authUrl',
|
||||
type: 'hidden' as NodePropertyTypes,
|
||||
default: 'https://acuityscheduling.com/oauth2/authorize',
|
||||
required: true,
|
||||
},
|
||||
{
|
||||
displayName: 'Access Token URL',
|
||||
name: 'accessTokenUrl',
|
||||
type: 'hidden' as NodePropertyTypes,
|
||||
default: 'https://acuityscheduling.com/oauth2/token',
|
||||
required: true,
|
||||
},
|
||||
{
|
||||
displayName: 'Scope',
|
||||
name: 'scope',
|
||||
type: 'hidden' as NodePropertyTypes,
|
||||
default: 'api-v1',
|
||||
required: true
|
||||
},
|
||||
{
|
||||
displayName: 'Auth URI Query Parameters',
|
||||
name: 'authQueryParameters',
|
||||
type: 'hidden' as NodePropertyTypes,
|
||||
default: '',
|
||||
},
|
||||
{
|
||||
displayName: 'Authentication',
|
||||
name: 'authentication',
|
||||
type: 'hidden' as NodePropertyTypes,
|
||||
default: 'body',
|
||||
},
|
||||
];
|
||||
}
|
|
@ -32,7 +32,25 @@ export class AcuitySchedulingTrigger implements INodeType {
|
|||
{
|
||||
name: 'acuitySchedulingApi',
|
||||
required: true,
|
||||
}
|
||||
displayOptions: {
|
||||
show: {
|
||||
authentication: [
|
||||
'apiKey',
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'acuitySchedulingOAuth2Api',
|
||||
required: true,
|
||||
displayOptions: {
|
||||
show: {
|
||||
authentication: [
|
||||
'oAuth2',
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
webhooks: [
|
||||
{
|
||||
|
@ -43,6 +61,23 @@ export class AcuitySchedulingTrigger implements INodeType {
|
|||
},
|
||||
],
|
||||
properties: [
|
||||
{
|
||||
displayName: 'Authentication',
|
||||
name: 'authentication',
|
||||
type: 'options',
|
||||
options: [
|
||||
{
|
||||
name: 'API Key',
|
||||
value: 'apiKey',
|
||||
},
|
||||
{
|
||||
name: 'OAuth2',
|
||||
value: 'oAuth2',
|
||||
},
|
||||
],
|
||||
default: 'apiKey',
|
||||
description: 'Method of authentication.',
|
||||
},
|
||||
{
|
||||
displayName: 'Event',
|
||||
name: 'event',
|
||||
|
|
|
@ -9,34 +9,39 @@ import {
|
|||
import { IDataObject } from 'n8n-workflow';
|
||||
|
||||
export async function acuitySchedulingApiRequest(this: IHookFunctions | IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions | IWebhookFunctions, method: string, resource: string, body: any = {}, qs: IDataObject = {}, uri?: string, option: IDataObject = {}): Promise<any> { // tslint:disable-line:no-any
|
||||
const credentials = this.getCredentials('acuitySchedulingApi');
|
||||
if (credentials === undefined) {
|
||||
throw new Error('No credentials got returned!');
|
||||
}
|
||||
const authenticationMethod = this.getNodeParameter('authentication', 0);
|
||||
|
||||
const options: OptionsWithUri = {
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
auth: {
|
||||
user: credentials.userId as string,
|
||||
password: credentials.apiKey as string,
|
||||
},
|
||||
auth: {},
|
||||
method,
|
||||
qs,
|
||||
body,
|
||||
uri: uri ||`https://acuityscheduling.com/api/v1${resource}`,
|
||||
json: true
|
||||
};
|
||||
|
||||
try {
|
||||
return await this.helpers.request!(options);
|
||||
} catch (error) {
|
||||
if (authenticationMethod === 'accessToken') {
|
||||
const credentials = this.getCredentials('acuitySchedulingApi');
|
||||
if (credentials === undefined) {
|
||||
throw new Error('No credentials got returned!');
|
||||
}
|
||||
|
||||
let errorMessage = error.message;
|
||||
if (error.response.body && error.response.body.message) {
|
||||
errorMessage = `[${error.response.body.status_code}] ${error.response.body.message}`;
|
||||
options.auth = {
|
||||
user: credentials.userId as string,
|
||||
password: credentials.apiKey as string,
|
||||
};
|
||||
|
||||
return await this.helpers.request!(options);
|
||||
} else {
|
||||
delete options.auth;
|
||||
//@ts-ignore
|
||||
return await this.helpers.requestOAuth2!.call(this, 'acuitySchedulingOAuth2Api', options, true);
|
||||
}
|
||||
|
||||
throw new Error('Acuity Scheduling Error: ' + errorMessage);
|
||||
} catch (error) {
|
||||
throw new Error('Acuity Scheduling Error: ' + error.message);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,6 +29,7 @@
|
|||
"dist/credentials/ActiveCampaignApi.credentials.js",
|
||||
"dist/credentials/AgileCrmApi.credentials.js",
|
||||
"dist/credentials/AcuitySchedulingApi.credentials.js",
|
||||
"dist/credentials/AcuitySchedulingOAuth2Api.credentials.js",
|
||||
"dist/credentials/AirtableApi.credentials.js",
|
||||
"dist/credentials/Amqp.credentials.js",
|
||||
"dist/credentials/AsanaApi.credentials.js",
|
||||
|
|
Loading…
Reference in a new issue