mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 10:02:05 +00:00
add OAuth2
This commit is contained in:
@@ -9,21 +9,11 @@ import {
|
||||
import { IDataObject } from 'n8n-workflow';
|
||||
import * as _ from 'lodash';
|
||||
|
||||
export async function zoomApiRequest(
|
||||
this: IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions,
|
||||
method: string,
|
||||
resource: string,
|
||||
body: object = {},
|
||||
query: object = {},
|
||||
headers: {} | undefined = undefined,
|
||||
option: {} = {}
|
||||
): Promise<any> {
|
||||
export async function zoomApiRequest(this: IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions, method: string, resource: string, body: object = {}, query: object = {}, headers: {} | undefined = undefined, option: {} = {}): Promise<any> { // tslint:disable-line:no-any
|
||||
|
||||
// tslint:disable-line:no-any
|
||||
const authenticationMethod = this.getNodeParameter(
|
||||
'authentication',
|
||||
0,
|
||||
'accessToken'
|
||||
) as string;
|
||||
const authenticationMethod = this.getNodeParameter('authentication', 0, 'accessToken') as string;
|
||||
|
||||
let options: OptionsWithUri = {
|
||||
method,
|
||||
headers: headers || {
|
||||
@@ -31,7 +21,7 @@ export async function zoomApiRequest(
|
||||
},
|
||||
body,
|
||||
qs: query,
|
||||
uri: `https://zoom.us/oauth${resource}`,
|
||||
uri: `https://api.zoom.us/v2${resource}`,
|
||||
json: true
|
||||
};
|
||||
options = Object.assign({}, options, option);
|
||||
@@ -41,6 +31,8 @@ export async function zoomApiRequest(
|
||||
if (Object.keys(query).length === 0) {
|
||||
delete options.qs;
|
||||
}
|
||||
console.log("options");
|
||||
console.log(options);
|
||||
try {
|
||||
if (authenticationMethod === 'accessToken') {
|
||||
const credentials = this.getCredentials('zoomApi');
|
||||
@@ -48,15 +40,24 @@ export async function zoomApiRequest(
|
||||
throw new Error('No credentials got returned!');
|
||||
}
|
||||
options.headers!.Authorization = `Bearer ${credentials.accessToken}`;
|
||||
console.log("options if");
|
||||
console.log(options);
|
||||
//@ts-ignore
|
||||
|
||||
return await this.helpers.request(options);
|
||||
} else {
|
||||
console.log("options else");
|
||||
console.log(options);
|
||||
let credentials = this.getCredentials('zoomOAuth2Api');
|
||||
// let oauthtoken1 = credentials!.oauthTokenData;
|
||||
|
||||
|
||||
console.log(credentials);
|
||||
console.log("credss");
|
||||
|
||||
//@ts-ignore
|
||||
return await this.helpers.requestOAuth2.call(
|
||||
this,
|
||||
'zoomOAuth2Api',
|
||||
options
|
||||
);
|
||||
|
||||
return await this.helpers.requestOAuth2.call(this, 'zoomOAuth2Api', options);
|
||||
}
|
||||
} catch (error) {
|
||||
if (error.statusCode === 401) {
|
||||
@@ -66,16 +67,17 @@ export async function zoomApiRequest(
|
||||
|
||||
if (error.response && error.response.body && error.response.body.message) {
|
||||
// Try to return the error prettier
|
||||
throw new Error(
|
||||
`Zoom error response [${error.statusCode}]: ${error.response.body.message}`
|
||||
);
|
||||
throw new Error(`Zoom error response [${error.statusCode}]: ${error.response.body.message}`);
|
||||
}
|
||||
|
||||
// If that data does not exist for some reason return the actual error
|
||||
throw error;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
export async function zoomApiRequestAllItems(
|
||||
this: IExecuteFunctions | ILoadOptionsFunctions,
|
||||
propertyName: string,
|
||||
|
||||
Reference in New Issue
Block a user