diff --git a/packages/cli/src/Server.ts b/packages/cli/src/Server.ts index 365bb1765b..560636029b 100644 --- a/packages/cli/src/Server.ts +++ b/packages/cli/src/Server.ts @@ -979,7 +979,7 @@ class App { // Save the credentials in DB await Db.collections.Credentials!.update(state.cid, newCredentialsData); - res.sendFile(pathResolve('templates/oauth-callback.html')); + res.sendFile(pathResolve('../templates/oauth-callback.html')); }); diff --git a/packages/nodes-base/nodes/Github/GenericFunctions.ts b/packages/nodes-base/nodes/Github/GenericFunctions.ts index 0b4c8452ab..b851eefe50 100644 --- a/packages/nodes-base/nodes/Github/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Github/GenericFunctions.ts @@ -17,17 +17,24 @@ import { * @returns {Promise} */ export async function githubApiRequest(this: IHookFunctions | IExecuteFunctions, method: string, endpoint: string, body: object, query?: object): Promise { // tslint:disable-line:no-any - const credentials = this.getCredentials('githubApi'); - if (credentials === undefined) { - throw new Error('No credentials got returned!'); + const githubApiCredentials = this.getCredentials('githubApi'); + const oAuth2ApiCrendetials = this.getCredentials('oAuth2Api'); + let headers = {} + if (githubApiCredentials !== undefined) { + headers = { + Authorization: `token ${githubApiCredentials.accessToken}`, + 'User-Agent': githubApiCredentials.user, + }; + } else { + const { access_token } = oAuth2ApiCrendetials!.oauthTokenData as IDataObject; + headers = { + Authorization: `token ${access_token}`, + 'User-Agent': 'Node js', + }; } - const options = { method, - headers: { - 'Authorization': `token ${credentials.accessToken}`, - 'User-Agent': credentials.user, - }, + headers, body, qs: query, uri: `https://api.github.com${endpoint}`, diff --git a/packages/nodes-base/nodes/Github/Github.node.ts b/packages/nodes-base/nodes/Github/Github.node.ts index 6174a1bd47..a8588b0cdd 100644 --- a/packages/nodes-base/nodes/Github/Github.node.ts +++ b/packages/nodes-base/nodes/Github/Github.node.ts @@ -33,9 +33,44 @@ export class Github implements INodeType { { name: 'githubApi', required: true, - } + displayOptions: { + show: { + authentication: [ + 'accessToken', + ], + }, + }, + }, + { + name: 'oAuth2Api', + required: true, + displayOptions: { + show: { + authentication: [ + 'oauth2', + ], + }, + }, + }, ], properties: [ + { + displayName: 'Authentication', + name: 'authentication', + type: 'options', + options: [ + { + name: 'Access Token', + value: 'accessToken', + }, + { + name: 'OAuth2', + value: 'oauth2', + }, + ], + default: 'accessToken', + description: 'The resource to operate on.', + }, { displayName: 'Resource', name: 'resource', @@ -1088,12 +1123,6 @@ export class Github implements INodeType { const items = this.getInputData(); const returnData: IDataObject[] = []; - const credentials = this.getCredentials('githubApi'); - - if (credentials === undefined) { - throw new Error('No credentials got returned!'); - } - // Operations which overwrite the returned data const overwriteDataOperations = [ 'file:create',