mirror of
https://github.com/n8n-io/n8n.git
synced 2025-02-21 02:56:40 -08:00
⚡ Add OAuth2 support to Monday.com node (#1642)
This commit is contained in:
parent
d87d497371
commit
1a0e129921
|
@ -0,0 +1,52 @@
|
||||||
|
import {
|
||||||
|
ICredentialType,
|
||||||
|
NodePropertyTypes,
|
||||||
|
} from 'n8n-workflow';
|
||||||
|
|
||||||
|
const scopes = [
|
||||||
|
'boards:write',
|
||||||
|
'boards:read',
|
||||||
|
];
|
||||||
|
|
||||||
|
export class MondayComOAuth2Api implements ICredentialType {
|
||||||
|
name = 'mondayComOAuth2Api';
|
||||||
|
extends = [
|
||||||
|
'oAuth2Api',
|
||||||
|
];
|
||||||
|
displayName = 'Monday.com OAuth2 API';
|
||||||
|
documentationUrl = 'monday';
|
||||||
|
properties = [
|
||||||
|
{
|
||||||
|
displayName: 'Authorization URL',
|
||||||
|
name: 'authUrl',
|
||||||
|
type: 'hidden' as NodePropertyTypes,
|
||||||
|
default: 'https://auth.monday.com/oauth2/authorize',
|
||||||
|
required: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
displayName: 'Access Token URL',
|
||||||
|
name: 'accessTokenUrl',
|
||||||
|
type: 'hidden' as NodePropertyTypes,
|
||||||
|
default: 'https://auth.monday.com/oauth2/token',
|
||||||
|
required: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
displayName: 'Scope',
|
||||||
|
name: 'scope',
|
||||||
|
type: 'hidden' as NodePropertyTypes,
|
||||||
|
default: scopes.join(' '),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
displayName: 'Auth URI Query Parameters',
|
||||||
|
name: 'authQueryParameters',
|
||||||
|
type: 'hidden' as NodePropertyTypes,
|
||||||
|
default: '',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
displayName: 'Authentication',
|
||||||
|
name: 'authentication',
|
||||||
|
type: 'hidden' as NodePropertyTypes,
|
||||||
|
default: 'body',
|
||||||
|
},
|
||||||
|
];
|
||||||
|
}
|
|
@ -18,19 +18,13 @@ import {
|
||||||
} from 'lodash';
|
} from 'lodash';
|
||||||
|
|
||||||
export async function mondayComApiRequest(this: IExecuteFunctions | IWebhookFunctions | IHookFunctions | ILoadOptionsFunctions, body: any = {}, option: IDataObject = {}): Promise<any> { // tslint:disable-line:no-any
|
export async function mondayComApiRequest(this: IExecuteFunctions | IWebhookFunctions | IHookFunctions | ILoadOptionsFunctions, body: any = {}, option: IDataObject = {}): Promise<any> { // tslint:disable-line:no-any
|
||||||
|
const authenticationMethod = this.getNodeParameter('authentication', 0) as string;
|
||||||
const credentials = this.getCredentials('mondayComApi');
|
|
||||||
|
|
||||||
if (credentials === undefined) {
|
|
||||||
throw new Error('No credentials got returned!');
|
|
||||||
}
|
|
||||||
|
|
||||||
const endpoint = 'https://api.monday.com/v2/';
|
const endpoint = 'https://api.monday.com/v2/';
|
||||||
|
|
||||||
let options: OptionsWithUri = {
|
let options: OptionsWithUri = {
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
'Authorization': credentials.apiToken,
|
|
||||||
},
|
},
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
body,
|
body,
|
||||||
|
@ -39,7 +33,16 @@ export async function mondayComApiRequest(this: IExecuteFunctions | IWebhookFunc
|
||||||
};
|
};
|
||||||
options = Object.assign({}, options, option);
|
options = Object.assign({}, options, option);
|
||||||
try {
|
try {
|
||||||
return await this.helpers.request!(options);
|
if (authenticationMethod === 'accessToken') {
|
||||||
|
const credentials = this.getCredentials('mondayComApi') as IDataObject;
|
||||||
|
|
||||||
|
options.headers = { Authorization: `Bearer ${credentials.apiToken}` };
|
||||||
|
|
||||||
|
return await this.helpers.request!(options);
|
||||||
|
} else {
|
||||||
|
|
||||||
|
return await this.helpers.requestOAuth2!.call(this, 'mondayComOAuth2Api', options);
|
||||||
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (error.response) {
|
if (error.response) {
|
||||||
const errorMessage = error.response.body.error_message;
|
const errorMessage = error.response.body.error_message;
|
||||||
|
|
|
@ -64,9 +64,44 @@ export class MondayCom implements INodeType {
|
||||||
{
|
{
|
||||||
name: 'mondayComApi',
|
name: 'mondayComApi',
|
||||||
required: true,
|
required: true,
|
||||||
|
displayOptions: {
|
||||||
|
show: {
|
||||||
|
authentication: [
|
||||||
|
'accessToken',
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'mondayComOAuth2Api',
|
||||||
|
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',
|
||||||
|
|
|
@ -160,6 +160,7 @@
|
||||||
"dist/credentials/MindeeInvoiceApi.credentials.js",
|
"dist/credentials/MindeeInvoiceApi.credentials.js",
|
||||||
"dist/credentials/MoceanApi.credentials.js",
|
"dist/credentials/MoceanApi.credentials.js",
|
||||||
"dist/credentials/MondayComApi.credentials.js",
|
"dist/credentials/MondayComApi.credentials.js",
|
||||||
|
"dist/credentials/MondayComOAuth2Api.credentials.js",
|
||||||
"dist/credentials/MongoDb.credentials.js",
|
"dist/credentials/MongoDb.credentials.js",
|
||||||
"dist/credentials/Mqtt.credentials.js",
|
"dist/credentials/Mqtt.credentials.js",
|
||||||
"dist/credentials/Msg91Api.credentials.js",
|
"dist/credentials/Msg91Api.credentials.js",
|
||||||
|
|
Loading…
Reference in a new issue