Merge branch 'ajmeredith1200-master'

This commit is contained in:
Jan Oberhauser 2022-06-03 19:42:43 +02:00
commit 9bbe88f462
3 changed files with 296 additions and 428 deletions

View file

@ -1,4 +1,6 @@
import { import {
IAuthenticateHeaderAuth,
ICredentialTestRequest,
ICredentialType, ICredentialType,
INodeProperties, INodeProperties,
} from 'n8n-workflow'; } from 'n8n-workflow';
@ -28,4 +30,18 @@ export class GithubApi implements ICredentialType {
default: '', default: '',
}, },
]; ];
authenticate: IAuthenticateHeaderAuth = {
type: 'headerAuth',
properties: {
name: 'Authorization',
value: '=token {{$credentials?.accessToken}}',
},
};
test: ICredentialTestRequest = {
request: {
baseURL: '={{$credentials?.server}}',
url: '/user',
method: 'GET',
},
};
} }

View file

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

File diff suppressed because it is too large Load diff