Skip to content

Commit

Permalink
🔀 Merge branch 'master' of https://github.com/ajmeredith1200/n8n into…
Browse files Browse the repository at this point in the history
… ajmeredith1200-master
  • Loading branch information
janober committed Jun 3, 2022
2 parents 70ae90f + 2ca2700 commit 527ce7c
Show file tree
Hide file tree
Showing 3 changed files with 297 additions and 429 deletions.
16 changes: 16 additions & 0 deletions packages/nodes-base/credentials/GithubApi.credentials.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import {
IAuthenticateHeaderAuth,
ICredentialTestRequest,
ICredentialType,
INodeProperties,
} from 'n8n-workflow';
Expand Down Expand Up @@ -28,4 +30,18 @@ export class GithubApi implements ICredentialType {
default: '',
},
];
authenticate: IAuthenticateHeaderAuth = {
type: 'headerAuth',
properties: {
name: 'Authorization',
value: '=token {{$credentials?.accessToken}}',
},
};
test: ICredentialTestRequest = {
request: {
baseURL: '={{$credentials?.server}}',
url: '/user',
method: 'GET',
},
};
}
10 changes: 5 additions & 5 deletions packages/nodes-base/nodes/Github/GenericFunctions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Loading

0 comments on commit 527ce7c

Please sign in to comment.