mirror of
https://github.com/n8n-io/n8n.git
synced 2024-11-09 22:24:05 -08:00
⚡ Clickup OAuth2 support (#649)
* OAuth2 credentials, genericFunctions needed config, UI options for oauth2 support * ⚡ Added options to decide when to to send the bearer * Fixed "undefined property split" issue * ⚡ Small fix * ⚡ Improvements to ClickUp-Node * ⚡ Improvements Co-authored-by: Rupenieks <ru@myos,co> Co-authored-by: ricardo <ricardoespinoza105@gmail.com> Co-authored-by: Ricardo Espinoza <ricardo@n8n.io>
This commit is contained in:
parent
7c54cf6ac2
commit
266112a8cb
|
@ -152,6 +152,12 @@ export function requestOAuth2(this: IAllExecuteFunctions, credentialsType: strin
|
|||
// on the token-type used.
|
||||
const newRequestOptions = token.sign(requestOptions as clientOAuth2.RequestObject);
|
||||
|
||||
// If keep bearer is false remove the it from the authorization header
|
||||
if (oAuth2Options?.keepBearer === false) {
|
||||
//@ts-ignore
|
||||
newRequestOptions?.headers?.Authorization = newRequestOptions?.headers?.Authorization.split(' ')[1];
|
||||
}
|
||||
|
||||
return this.helpers.request!(newRequestOptions)
|
||||
.catch(async (error: IResponseError) => {
|
||||
// TODO: Check if also other codes are possible
|
||||
|
|
|
@ -0,0 +1,47 @@
|
|||
import {
|
||||
ICredentialType,
|
||||
NodePropertyTypes,
|
||||
} from 'n8n-workflow';
|
||||
|
||||
export class ClickUpOAuth2Api implements ICredentialType {
|
||||
name = 'clickUpOAuth2Api';
|
||||
extends = [
|
||||
'oAuth2Api',
|
||||
];
|
||||
displayName = 'ClickUp OAuth2 API';
|
||||
properties = [
|
||||
{
|
||||
displayName: 'Authorization URL',
|
||||
name: 'authUrl',
|
||||
type: 'hidden' as NodePropertyTypes,
|
||||
default: 'https://app.clickup.com/api',
|
||||
required: true,
|
||||
},
|
||||
{
|
||||
displayName: 'Access Token URL',
|
||||
name: 'accessTokenUrl',
|
||||
type: 'hidden' as NodePropertyTypes,
|
||||
default: 'https://api.clickup.com/api/v2/oauth/token',
|
||||
required: true,
|
||||
},
|
||||
{
|
||||
displayName: 'Scope',
|
||||
name: 'scope',
|
||||
type: 'hidden' as NodePropertyTypes,
|
||||
default: '',
|
||||
},
|
||||
{
|
||||
displayName: 'Auth URI Query Parameters',
|
||||
name: 'authQueryParameters',
|
||||
type: 'hidden' as NodePropertyTypes,
|
||||
default: '',
|
||||
},
|
||||
{
|
||||
displayName: 'Authentication',
|
||||
name: 'authentication',
|
||||
type: 'hidden' as NodePropertyTypes,
|
||||
default: 'body',
|
||||
description: 'Resource to consume.',
|
||||
},
|
||||
];
|
||||
}
|
|
@ -99,9 +99,43 @@ export class ClickUp implements INodeType {
|
|||
{
|
||||
name: 'clickUpApi',
|
||||
required: true,
|
||||
displayOptions: {
|
||||
show: {
|
||||
authentication: [
|
||||
'accessToken',
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'clickUpOAuth2Api',
|
||||
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',
|
||||
},
|
||||
{
|
||||
displayName: 'Resource',
|
||||
name: 'resource',
|
||||
|
|
|
@ -34,9 +34,27 @@ export class ClickUpTrigger implements INodeType {
|
|||
outputs: ['main'],
|
||||
credentials: [
|
||||
{
|
||||
name: 'clickUpApi',
|
||||
name: 'clickupApi',
|
||||
required: true,
|
||||
}
|
||||
displayOptions: {
|
||||
show: {
|
||||
authentication: [
|
||||
'accessToken',
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'clickUpOAuth2Api',
|
||||
required: true,
|
||||
displayOptions: {
|
||||
show: {
|
||||
authentication: [
|
||||
'oAuth2',
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
webhooks: [
|
||||
{
|
||||
|
@ -47,6 +65,22 @@ export class ClickUpTrigger implements INodeType {
|
|||
},
|
||||
],
|
||||
properties: [
|
||||
{
|
||||
displayName: 'Authentication',
|
||||
name: 'authentication',
|
||||
type: 'options',
|
||||
options: [
|
||||
{
|
||||
name: 'Access Token',
|
||||
value: 'accessToken',
|
||||
},
|
||||
{
|
||||
name: 'OAuth2',
|
||||
value: 'oAuth2',
|
||||
},
|
||||
],
|
||||
default: 'accessToken',
|
||||
},
|
||||
{
|
||||
displayName: 'Team',
|
||||
name: 'team',
|
||||
|
|
|
@ -12,17 +12,12 @@ import {
|
|||
|
||||
import {
|
||||
IDataObject,
|
||||
IOAuth2Options,
|
||||
} from 'n8n-workflow';
|
||||
|
||||
export async function clickupApiRequest(this: IHookFunctions | IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions | IWebhookFunctions, method: string, resource: string, body: any = {}, qs: IDataObject = {}, uri?: string, option: IDataObject = {}): Promise<any> { // tslint:disable-line:no-any
|
||||
const credentials = this.getCredentials('clickUpApi');
|
||||
if (credentials === undefined) {
|
||||
throw new Error('No credentials got returned!');
|
||||
}
|
||||
|
||||
const options: OptionsWithUri = {
|
||||
headers: {
|
||||
Authorization: credentials.accessToken,
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
method,
|
||||
|
@ -31,15 +26,39 @@ export async function clickupApiRequest(this: IHookFunctions | IExecuteFunctions
|
|||
uri: uri ||`https://api.clickup.com/api/v2${resource}`,
|
||||
json: true
|
||||
};
|
||||
|
||||
try {
|
||||
return await this.helpers.request!(options);
|
||||
} catch (error) {
|
||||
const authenticationMethod = this.getNodeParameter('authentication', 0) as string;
|
||||
|
||||
if (authenticationMethod === 'accessToken') {
|
||||
|
||||
const credentials = this.getCredentials('clickUpApi');
|
||||
|
||||
if (credentials === undefined) {
|
||||
throw new Error('No credentials got returned!');
|
||||
}
|
||||
|
||||
options.headers!['Authorization'] = credentials.accessToken;
|
||||
return await this.helpers.request!(options);
|
||||
|
||||
} else {
|
||||
|
||||
const oAuth2Options: IOAuth2Options = {
|
||||
keepBearer: false,
|
||||
tokenType: 'Bearer',
|
||||
};
|
||||
// @ts-ignore
|
||||
return await this.helpers.requestOAuth2!.call(this, 'clickUpOAuth2Api', options, oAuth2Options);
|
||||
}
|
||||
|
||||
} catch(error) {
|
||||
let errorMessage = error;
|
||||
if (error.err) {
|
||||
errorMessage = error.err;
|
||||
}
|
||||
throw new Error('ClickUp Error: ' + errorMessage);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export async function clickupApiRequestAllItems(this: IHookFunctions | IExecuteFunctions| ILoadOptionsFunctions, propertyName: string ,method: string, resource: string, body: any = {}, query: IDataObject = {}): Promise<any> { // tslint:disable-line:no-any
|
||||
|
|
|
@ -44,6 +44,7 @@
|
|||
"dist/credentials/CircleCiApi.credentials.js",
|
||||
"dist/credentials/ClearbitApi.credentials.js",
|
||||
"dist/credentials/ClickUpApi.credentials.js",
|
||||
"dist/credentials/ClickUpOAuth2Api.credentials.js",
|
||||
"dist/credentials/ClockifyApi.credentials.js",
|
||||
"dist/credentials/CockpitApi.credentials.js",
|
||||
"dist/credentials/CodaApi.credentials.js",
|
||||
|
|
|
@ -16,6 +16,7 @@ export interface IOAuth2Options {
|
|||
includeCredentialsOnRefreshOnBody?: boolean;
|
||||
property?: string;
|
||||
tokenType?: string;
|
||||
keepBearer?: boolean;
|
||||
}
|
||||
|
||||
export interface IConnection {
|
||||
|
|
Loading…
Reference in a new issue