Skip to content

Commit 9bbe88f

Browse files
committed
Merge branch 'ajmeredith1200-master'
2 parents 70ae90f + 527ce7c commit 9bbe88f

File tree

3 files changed

+297
-429
lines changed

3 files changed

+297
-429
lines changed

packages/nodes-base/credentials/GithubApi.credentials.ts

+16
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import {
2+
IAuthenticateHeaderAuth,
3+
ICredentialTestRequest,
24
ICredentialType,
35
INodeProperties,
46
} from 'n8n-workflow';
@@ -28,4 +30,18 @@ export class GithubApi implements ICredentialType {
2830
default: '',
2931
},
3032
];
33+
authenticate: IAuthenticateHeaderAuth = {
34+
type: 'headerAuth',
35+
properties: {
36+
name: 'Authorization',
37+
value: '=token {{$credentials?.accessToken}}',
38+
},
39+
};
40+
test: ICredentialTestRequest = {
41+
request: {
42+
baseURL: '={{$credentials?.server}}',
43+
url: '/user',
44+
method: 'GET',
45+
},
46+
};
3147
}

packages/nodes-base/nodes/Github/GenericFunctions.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -37,23 +37,23 @@ export async function githubApiRequest(this: IHookFunctions | IExecuteFunctions,
3737

3838
try {
3939
const authenticationMethod = this.getNodeParameter('authentication', 0, 'accessToken') as string;
40+
let credentialType = '';
4041

4142
if (authenticationMethod === 'accessToken') {
4243
const credentials = await this.getCredentials('githubApi');
44+
credentialType = 'githubApi';
4345

4446
const baseUrl = credentials!.server || 'https://api.github.com';
4547
options.uri = `${baseUrl}${endpoint}`;
46-
47-
options.headers!.Authorization = `token ${credentials.accessToken}`;
48-
return await this.helpers.request(options);
4948
} else {
5049
const credentials = await this.getCredentials('githubOAuth2Api');
50+
credentialType = 'githubOAuth2Api';
5151

5252
const baseUrl = credentials.server || 'https://api.github.com';
5353
options.uri = `${baseUrl}${endpoint}`;
54-
//@ts-ignore
55-
return await this.helpers.requestOAuth2.call(this, 'githubOAuth2Api', options);
5654
}
55+
56+
return await this.helpers.requestWithAuthentication.call(this, credentialType, options);
5757
} catch (error) {
5858
throw new NodeApiError(this.getNode(), error);
5959
}

0 commit comments

Comments
 (0)