🔀 Merge branch 'feature/github-oauth' of https://github.com/RicardoE105/n8n into RicardoE105-feature/github-oauth

This commit is contained in:
Jan Oberhauser 2020-02-09 14:03:57 -08:00
commit ec68712f63
3 changed files with 52 additions and 16 deletions

View file

@ -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'));
});

View file

@ -17,17 +17,24 @@ import {
* @returns {Promise<any>}
*/
export async function githubApiRequest(this: IHookFunctions | IExecuteFunctions, method: string, endpoint: string, body: object, query?: object): Promise<any> { // 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}`,

View file

@ -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',