mirror of
https://github.com/n8n-io/n8n.git
synced 2025-02-02 07:01:30 -08:00
✨ Github OAuth support
This commit is contained in:
parent
928bf4dc68
commit
96741460e3
|
@ -979,7 +979,7 @@ class App {
|
||||||
// Save the credentials in DB
|
// Save the credentials in DB
|
||||||
await Db.collections.Credentials!.update(state.cid, newCredentialsData);
|
await Db.collections.Credentials!.update(state.cid, newCredentialsData);
|
||||||
|
|
||||||
res.sendFile(pathResolve('templates/oauth-callback.html'));
|
res.sendFile(pathResolve('../templates/oauth-callback.html'));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -17,17 +17,24 @@ import {
|
||||||
* @returns {Promise<any>}
|
* @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
|
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');
|
const githubApiCredentials = this.getCredentials('githubApi');
|
||||||
if (credentials === undefined) {
|
const oAuth2ApiCrendetials = this.getCredentials('oAuth2Api');
|
||||||
throw new Error('No credentials got returned!');
|
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 = {
|
const options = {
|
||||||
method,
|
method,
|
||||||
headers: {
|
headers,
|
||||||
'Authorization': `token ${credentials.accessToken}`,
|
|
||||||
'User-Agent': credentials.user,
|
|
||||||
},
|
|
||||||
body,
|
body,
|
||||||
qs: query,
|
qs: query,
|
||||||
uri: `https://api.github.com${endpoint}`,
|
uri: `https://api.github.com${endpoint}`,
|
||||||
|
|
|
@ -33,9 +33,44 @@ export class Github implements INodeType {
|
||||||
{
|
{
|
||||||
name: 'githubApi',
|
name: 'githubApi',
|
||||||
required: true,
|
required: true,
|
||||||
}
|
displayOptions: {
|
||||||
|
show: {
|
||||||
|
authentication: [
|
||||||
|
'accessToken',
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'oAuth2Api',
|
||||||
|
required: true,
|
||||||
|
displayOptions: {
|
||||||
|
show: {
|
||||||
|
authentication: [
|
||||||
|
'oauth2',
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
],
|
],
|
||||||
properties: [
|
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',
|
displayName: 'Resource',
|
||||||
name: 'resource',
|
name: 'resource',
|
||||||
|
@ -1088,12 +1123,6 @@ export class Github implements INodeType {
|
||||||
const items = this.getInputData();
|
const items = this.getInputData();
|
||||||
const returnData: IDataObject[] = [];
|
const returnData: IDataObject[] = [];
|
||||||
|
|
||||||
const credentials = this.getCredentials('githubApi');
|
|
||||||
|
|
||||||
if (credentials === undefined) {
|
|
||||||
throw new Error('No credentials got returned!');
|
|
||||||
}
|
|
||||||
|
|
||||||
// Operations which overwrite the returned data
|
// Operations which overwrite the returned data
|
||||||
const overwriteDataOperations = [
|
const overwriteDataOperations = [
|
||||||
'file:create',
|
'file:create',
|
||||||
|
|
Loading…
Reference in a new issue