mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 10:02:05 +00:00
Credentials, oauth2 supported genericfunctions, oauth2 UI mod
This commit is contained in:
@@ -9,14 +9,10 @@ import {
|
||||
import { IDataObject } from 'n8n-workflow';
|
||||
|
||||
export async function webflowApiRequest(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('webflowApi');
|
||||
if (credentials === undefined) {
|
||||
throw new Error('No credentials got returned!');
|
||||
}
|
||||
const authenticationMethod = this.getNodeParameter('authentication', 0);
|
||||
|
||||
let options: OptionsWithUri = {
|
||||
headers: {
|
||||
authorization: `Bearer ${credentials.accessToken}`,
|
||||
'accept-version': '1.0.0',
|
||||
},
|
||||
method,
|
||||
@@ -31,14 +27,19 @@ export async function webflowApiRequest(this: IHookFunctions | IExecuteFunctions
|
||||
}
|
||||
|
||||
try {
|
||||
return await this.helpers.request!(options);
|
||||
} catch (error) {
|
||||
if (authenticationMethod === 'accessToken') {
|
||||
const credentials = this.getCredentials('webflowApi');
|
||||
if (credentials === undefined) {
|
||||
throw new Error('No credentials got returned!');
|
||||
}
|
||||
|
||||
let errorMessage = error.message;
|
||||
if (error.response.body && error.response.body.err) {
|
||||
errorMessage = error.response.body.err;
|
||||
options.headers!['authorization'] = `Bearer ${credentials.accessToken}`;
|
||||
|
||||
return await this.helpers.request!(options);
|
||||
} else {
|
||||
return await this.helpers.requestOAuth2!.call(this, 'webflowOAuth2Api', options);
|
||||
}
|
||||
|
||||
throw new Error('Webflow Error: ' + errorMessage);
|
||||
} catch (error) {
|
||||
throw new Error('Webflow Error: ' + error.code + error.msg);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user