mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 10:02:05 +00:00
🔀 Merge branch 'master' into oauth-support
This commit is contained in:
@@ -19,7 +19,6 @@ import {
|
||||
* @returns {Promise<any>}
|
||||
*/
|
||||
export async function githubApiRequest(this: IHookFunctions | IExecuteFunctions, method: string, endpoint: string, body: object, query?: object): Promise<any> { // tslint:disable-line:no-any
|
||||
const authenticationMethod = this.getNodeParameter('authentication', 0, 'accessToken') as string;
|
||||
|
||||
const options: OptionsWithUri = {
|
||||
method,
|
||||
@@ -28,19 +27,30 @@ export async function githubApiRequest(this: IHookFunctions | IExecuteFunctions,
|
||||
},
|
||||
body,
|
||||
qs: query,
|
||||
uri: `https://api.github.com${endpoint}`,
|
||||
uri: '',
|
||||
json: true
|
||||
};
|
||||
|
||||
try {
|
||||
const authenticationMethod = this.getNodeParameter('authentication', 0, 'accessToken') as string;
|
||||
|
||||
if (authenticationMethod === 'accessToken') {
|
||||
const credentials = this.getCredentials('githubApi');
|
||||
if (credentials === undefined) {
|
||||
throw new Error('No credentials got returned!');
|
||||
}
|
||||
|
||||
const baseUrl = credentials!.server || 'https://api.github.com';
|
||||
options.uri = `${baseUrl}${endpoint}`;
|
||||
|
||||
options.headers!.Authorization = `token ${credentials.accessToken}`;
|
||||
return await this.helpers.request(options);
|
||||
} else {
|
||||
const credentials = this.getCredentials('githubOAuth2Api');
|
||||
|
||||
const baseUrl = credentials!.server || 'https://api.github.com';
|
||||
options.uri = `${baseUrl}${endpoint}`;
|
||||
|
||||
return await this.helpers.requestOAuth.call(this, 'githubOAuth2Api', options);
|
||||
}
|
||||
} catch (error) {
|
||||
|
||||
Reference in New Issue
Block a user