From fd970b13255417a03d3b239dcdff05ddda875bb9 Mon Sep 17 00:00:00 2001 From: Rupenieks Date: Mon, 15 Jun 2020 15:33:28 +0200 Subject: [PATCH] Credentials, UI setup. Has everything but a generic functions setup. Requires more functionality to give purpose to having OAuth2 authentication in the first place. --- .../DiscordOAuth2Api.credentials.ts | 47 +++++++++++++++++++ .../nodes-base/nodes/Discord/Discord.node.ts | 32 ++++++++++++- packages/nodes-base/package.json | 1 + 3 files changed, 78 insertions(+), 2 deletions(-) create mode 100644 packages/nodes-base/credentials/DiscordOAuth2Api.credentials.ts diff --git a/packages/nodes-base/credentials/DiscordOAuth2Api.credentials.ts b/packages/nodes-base/credentials/DiscordOAuth2Api.credentials.ts new file mode 100644 index 0000000000..cca1718d59 --- /dev/null +++ b/packages/nodes-base/credentials/DiscordOAuth2Api.credentials.ts @@ -0,0 +1,47 @@ +import { + ICredentialType, + NodePropertyTypes, +} from 'n8n-workflow'; + + +export class DiscordOAuth2Api implements ICredentialType { + name = 'discordOAuth2Api'; + extends = [ + 'oAuth2Api', + ]; + displayName = 'Discord OAuth2 API'; + properties = [ + { + displayName: 'Authorization URL', + name: 'authUrl', + type: 'hidden' as NodePropertyTypes, + default: 'https://discord.com/api/oauth2/authorize', + required: true, + }, + { + displayName: 'Access Token URL', + name: 'accessTokenUrl', + type: 'hidden' as NodePropertyTypes, + default: 'https://discord.com/api/oauth2/token', + required: true, + }, + { + displayName: 'Scope', + name: 'scope', + type: 'string' 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', + }, + ]; +} diff --git a/packages/nodes-base/nodes/Discord/Discord.node.ts b/packages/nodes-base/nodes/Discord/Discord.node.ts index fcd701f27b..c98a30a74a 100644 --- a/packages/nodes-base/nodes/Discord/Discord.node.ts +++ b/packages/nodes-base/nodes/Discord/Discord.node.ts @@ -21,7 +21,37 @@ export class Discord implements INodeType { }, inputs: ['main'], outputs: ['main'], + credentials: [ + { + name: 'discordOAuth2Api', + required: true, + displayOptions: { + show: { + authentication: [ + 'oAuth2', + ], + }, + }, + }, + ], properties: [ + { + displayName: 'Authentication', + name: 'authentication', + type: 'options', + options: [ + { + name: 'None', + value: 'none', + }, + { + name: 'OAuth2', + value: 'oAuth2', + }, + ], + default: 'none', + description: 'The resource to operate on.', + }, { displayName: 'Webhook URL', name: 'webhookUri', @@ -45,8 +75,6 @@ export class Discord implements INodeType { ], }; - - async execute(this: IExecuteFunctions): Promise { const items = this.getInputData(); const returnData: IDataObject[] = []; diff --git a/packages/nodes-base/package.json b/packages/nodes-base/package.json index 649bde4837..42a6fdb1af 100644 --- a/packages/nodes-base/package.json +++ b/packages/nodes-base/package.json @@ -45,6 +45,7 @@ "dist/credentials/CodaApi.credentials.js", "dist/credentials/CopperApi.credentials.js", "dist/credentials/CalendlyApi.credentials.js", + "dist/credentials/DiscordOAuth2Api.credentials.js", "dist/credentials/DisqusApi.credentials.js", "dist/credentials/DriftApi.credentials.js", "dist/credentials/DropboxApi.credentials.js",