credentials update

This commit is contained in:
Michael Kret
2022-05-31 10:46:20 +03:00
parent e6fef4b494
commit 2ca27006fd
3 changed files with 21 additions and 54 deletions

View File

@@ -37,23 +37,23 @@ export async function githubApiRequest(this: IHookFunctions | IExecuteFunctions,
try {
const authenticationMethod = this.getNodeParameter('authentication', 0, 'accessToken') as string;
let credentialType = '';
if (authenticationMethod === 'accessToken') {
const credentials = await this.getCredentials('githubApi');
credentialType = 'githubApi';
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 = await this.getCredentials('githubOAuth2Api');
credentialType = 'githubOAuth2Api';
const baseUrl = credentials.server || 'https://api.github.com';
options.uri = `${baseUrl}${endpoint}`;
//@ts-ignore
return await this.helpers.requestOAuth2.call(this, 'githubOAuth2Api', options);
}
return await this.helpers.requestWithAuthentication.call(this, credentialType, options);
} catch (error) {
throw new NodeApiError(this.getNode(), error);
}