mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 10:02:05 +00:00
OAuth2 support
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user