mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 18:12:04 +00:00
OAuth2 support
This commit is contained in:
@@ -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',
|
name: 'acuitySchedulingApi',
|
||||||
required: true,
|
required: true,
|
||||||
}
|
displayOptions: {
|
||||||
|
show: {
|
||||||
|
authentication: [
|
||||||
|
'accessToken',
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'acuitySchedulingOAuth2Api',
|
||||||
|
required: true,
|
||||||
|
displayOptions: {
|
||||||
|
show: {
|
||||||
|
authentication: [
|
||||||
|
'oAuth2',
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
],
|
],
|
||||||
webhooks: [
|
webhooks: [
|
||||||
{
|
{
|
||||||
@@ -43,6 +61,23 @@ export class AcuitySchedulingTrigger implements INodeType {
|
|||||||
},
|
},
|
||||||
],
|
],
|
||||||
properties: [
|
properties: [
|
||||||
|
{
|
||||||
|
displayName: 'Authentication',
|
||||||
|
name: 'authentication',
|
||||||
|
type: 'options',
|
||||||
|
options: [
|
||||||
|
{
|
||||||
|
name: 'Access Token',
|
||||||
|
value: 'accessToken',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'OAuth2',
|
||||||
|
value: 'oAuth2',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
default: 'accessToken',
|
||||||
|
description: 'The resource to operate on.',
|
||||||
|
},
|
||||||
{
|
{
|
||||||
displayName: 'Event',
|
displayName: 'Event',
|
||||||
name: 'event',
|
name: 'event',
|
||||||
|
|||||||
@@ -9,34 +9,39 @@ import {
|
|||||||
import { IDataObject } from 'n8n-workflow';
|
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
|
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');
|
const authenticationMethod = this.getNodeParameter('authentication', 0);
|
||||||
if (credentials === undefined) {
|
|
||||||
throw new Error('No credentials got returned!');
|
|
||||||
}
|
|
||||||
|
|
||||||
const options: OptionsWithUri = {
|
const options: OptionsWithUri = {
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
},
|
},
|
||||||
auth: {
|
auth: {},
|
||||||
user: credentials.userId as string,
|
|
||||||
password: credentials.apiKey as string,
|
|
||||||
},
|
|
||||||
method,
|
method,
|
||||||
qs,
|
qs,
|
||||||
body,
|
body,
|
||||||
uri: uri ||`https://acuityscheduling.com/api/v1${resource}`,
|
uri: uri ||`https://acuityscheduling.com/api/v1${resource}`,
|
||||||
json: true
|
json: true
|
||||||
};
|
};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return await this.helpers.request!(options);
|
if (authenticationMethod === 'accessToken') {
|
||||||
} catch (error) {
|
const credentials = this.getCredentials('acuitySchedulingApi');
|
||||||
|
if (credentials === undefined) {
|
||||||
|
throw new Error('No credentials got returned!');
|
||||||
|
}
|
||||||
|
|
||||||
let errorMessage = error.message;
|
options.auth = {
|
||||||
if (error.response.body && error.response.body.message) {
|
user: credentials.userId as string,
|
||||||
errorMessage = `[${error.response.body.status_code}] ${error.response.body.message}`;
|
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);
|
||||||
}
|
}
|
||||||
|
} catch (error) {
|
||||||
throw new Error('Acuity Scheduling Error: ' + errorMessage);
|
throw new Error('Acuity Scheduling Error: ' + error.message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,6 +29,7 @@
|
|||||||
"dist/credentials/ActiveCampaignApi.credentials.js",
|
"dist/credentials/ActiveCampaignApi.credentials.js",
|
||||||
"dist/credentials/AgileCrmApi.credentials.js",
|
"dist/credentials/AgileCrmApi.credentials.js",
|
||||||
"dist/credentials/AcuitySchedulingApi.credentials.js",
|
"dist/credentials/AcuitySchedulingApi.credentials.js",
|
||||||
|
"dist/credentials/AcuitySchedulingOAuth2Api.credentials.js",
|
||||||
"dist/credentials/AirtableApi.credentials.js",
|
"dist/credentials/AirtableApi.credentials.js",
|
||||||
"dist/credentials/Amqp.credentials.js",
|
"dist/credentials/Amqp.credentials.js",
|
||||||
"dist/credentials/AsanaApi.credentials.js",
|
"dist/credentials/AsanaApi.credentials.js",
|
||||||
|
|||||||
Reference in New Issue
Block a user