mirror of
https://github.com/n8n-io/n8n.git
synced 2025-03-05 20:50:17 -08:00
🚧 Setup
Added OAuth2 credentials, UI, generic functions changes
This commit is contained in:
parent
13f71d3af0
commit
de7a6d6dfb
|
@ -0,0 +1,80 @@
|
||||||
|
import {
|
||||||
|
ICredentialType,
|
||||||
|
NodePropertyTypes,
|
||||||
|
} from 'n8n-workflow';
|
||||||
|
|
||||||
|
|
||||||
|
export class BitlyOAuth2Api implements ICredentialType {
|
||||||
|
name = 'bitlyOAuth2Api';
|
||||||
|
displayName = 'Bitly OAuth2 API';
|
||||||
|
|
||||||
|
extends = [
|
||||||
|
'oAuth2Api',
|
||||||
|
];
|
||||||
|
properties = [
|
||||||
|
{
|
||||||
|
displayName: 'Authorization URL',
|
||||||
|
name: 'authUrl',
|
||||||
|
type: 'hidden' as NodePropertyTypes,
|
||||||
|
default: 'https://bitly.com/oauth/authorize',
|
||||||
|
required: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
displayName: 'Access Token URL',
|
||||||
|
name: 'accessTokenUrl',
|
||||||
|
type: 'hidden' as NodePropertyTypes,
|
||||||
|
default: 'https://api-ssl.bitly.com/oauth/access_token',
|
||||||
|
required: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
displayName: 'Client ID',
|
||||||
|
name: 'clientId',
|
||||||
|
type: 'string' as NodePropertyTypes,
|
||||||
|
default: '',
|
||||||
|
required: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
displayName: 'Client Secret',
|
||||||
|
name: 'clientSecret',
|
||||||
|
type: 'string' as NodePropertyTypes,
|
||||||
|
typeOptions: {
|
||||||
|
password: true,
|
||||||
|
},
|
||||||
|
default: '',
|
||||||
|
required: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
displayName: 'Scope',
|
||||||
|
name: 'scope',
|
||||||
|
type: 'hidden' as NodePropertyTypes,
|
||||||
|
default: '',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
displayName: 'Auth URI Query Parameters',
|
||||||
|
name: 'authQueryParameters',
|
||||||
|
type: 'hidden' as NodePropertyTypes,
|
||||||
|
default: '',
|
||||||
|
description: 'For some services additional query parameters have to be set which can be defined here.',
|
||||||
|
placeholder: 'access_type=offline',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
displayName: 'Authentication',
|
||||||
|
name: 'authentication',
|
||||||
|
type: 'options' as NodePropertyTypes,
|
||||||
|
options: [
|
||||||
|
{
|
||||||
|
name: 'Body',
|
||||||
|
value: 'body',
|
||||||
|
description: 'Send credentials in body',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'Header',
|
||||||
|
value: 'header',
|
||||||
|
description: 'Send credentials as Basic Auth header',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
default: 'header',
|
||||||
|
description: 'Resource to consume.',
|
||||||
|
},
|
||||||
|
];
|
||||||
|
}
|
|
@ -37,9 +37,44 @@ export class Bitly implements INodeType {
|
||||||
{
|
{
|
||||||
name: 'bitlyApi',
|
name: 'bitlyApi',
|
||||||
required: true,
|
required: true,
|
||||||
}
|
displayOptions: {
|
||||||
|
show: {
|
||||||
|
authentication: [
|
||||||
|
'accessToken',
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'bitlyOAuth2Api',
|
||||||
|
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',
|
||||||
|
|
|
@ -6,14 +6,12 @@ import {
|
||||||
ILoadOptionsFunctions,
|
ILoadOptionsFunctions,
|
||||||
} from 'n8n-core';
|
} from 'n8n-core';
|
||||||
import { IDataObject } from 'n8n-workflow';
|
import { IDataObject } from 'n8n-workflow';
|
||||||
|
import { attachmentFields } from '../Salesforce/AttachmentDescription';
|
||||||
|
|
||||||
export async function bitlyApiRequest(this: IHookFunctions | IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions, method: string, resource: string, body: any = {}, qs: IDataObject = {}, uri?: string, option: IDataObject = {}): Promise<any> { // tslint:disable-line:no-any
|
export async function bitlyApiRequest(this: IHookFunctions | IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions, method: string, resource: string, body: any = {}, qs: IDataObject = {}, uri?: string, option: IDataObject = {}): Promise<any> { // tslint:disable-line:no-any
|
||||||
const credentials = this.getCredentials('bitlyApi');
|
const authenticationMethod = this.getNodeParameter('authentication', 0) as string;
|
||||||
if (credentials === undefined) {
|
|
||||||
throw new Error('No credentials got returned!');
|
|
||||||
}
|
|
||||||
let options: OptionsWithUri = {
|
let options: OptionsWithUri = {
|
||||||
headers: { Authorization: `Bearer ${credentials.accessToken}`},
|
headers: {},
|
||||||
method,
|
method,
|
||||||
qs,
|
qs,
|
||||||
body,
|
body,
|
||||||
|
@ -24,10 +22,21 @@ export async function bitlyApiRequest(this: IHookFunctions | IExecuteFunctions |
|
||||||
if (Object.keys(options.body).length === 0) {
|
if (Object.keys(options.body).length === 0) {
|
||||||
delete options.body;
|
delete options.body;
|
||||||
}
|
}
|
||||||
try {
|
|
||||||
return await this.helpers.request!(options);
|
try{
|
||||||
} catch (err) {
|
if (authenticationMethod === 'accessToken') {
|
||||||
throw new Error(err);
|
const credentials = this.getCredentials('bitlyApi');
|
||||||
|
if (credentials === undefined) {
|
||||||
|
throw new Error('No credentials got returned!');
|
||||||
|
}
|
||||||
|
options.headers = { Authorization: `Bearer ${credentials.accessToken}`};
|
||||||
|
|
||||||
|
return await this.helpers.request!(options);
|
||||||
|
} else {
|
||||||
|
return await this.helpers.requestOAuth2!.call(this, 'bitlyOAuth2Api', options);
|
||||||
|
}
|
||||||
|
} catch(error) {
|
||||||
|
throw new Error(error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -37,6 +37,7 @@
|
||||||
"dist/credentials/BannerbearApi.credentials.js",
|
"dist/credentials/BannerbearApi.credentials.js",
|
||||||
"dist/credentials/BitbucketApi.credentials.js",
|
"dist/credentials/BitbucketApi.credentials.js",
|
||||||
"dist/credentials/BitlyApi.credentials.js",
|
"dist/credentials/BitlyApi.credentials.js",
|
||||||
|
"dist/credentials/BitlyOAuth2Api.credentials.js",
|
||||||
"dist/credentials/ChargebeeApi.credentials.js",
|
"dist/credentials/ChargebeeApi.credentials.js",
|
||||||
"dist/credentials/ClearbitApi.credentials.js",
|
"dist/credentials/ClearbitApi.credentials.js",
|
||||||
"dist/credentials/ClickUpApi.credentials.js",
|
"dist/credentials/ClickUpApi.credentials.js",
|
||||||
|
|
Loading…
Reference in a new issue