From ad414fb445a359c242a09eb368ebd912e91967fa Mon Sep 17 00:00:00 2001 From: Syed Mohammad Akhtar Rizvi <85864291+ShazanRizvi@users.noreply.github.com> Date: Wed, 17 Apr 2024 15:55:37 +0530 Subject: [PATCH] OauthFlowSetup --- .../DataSourceManager/DataSourceManager.jsx | 3 +- frontend/src/_components/DynamicForm.jsx | 2 + frontend/src/_components/Salesforce.jsx | 54 +++- marketplace/package-lock.json | 243 ++++++++++++++++++ marketplace/plugins/salesforce/lib/index.ts | 28 +- server/src/services/data_sources.service.ts | 5 +- 6 files changed, 321 insertions(+), 14 deletions(-) diff --git a/frontend/src/Editor/DataSourceManager/DataSourceManager.jsx b/frontend/src/Editor/DataSourceManager/DataSourceManager.jsx index 22f79e415b..fc3f8e9fb5 100644 --- a/frontend/src/Editor/DataSourceManager/DataSourceManager.jsx +++ b/frontend/src/Editor/DataSourceManager/DataSourceManager.jsx @@ -193,7 +193,8 @@ class DataSourceManagerComponent extends React.Component { createDataSource = () => { const { appId, options, selectedDataSource, selectedDataSourcePluginId, dataSourceMeta, dataSourceSchema } = this.state; - const OAuthDs = ['slack', 'zendesk', 'googlesheets']; + console.log('selectedDataSource from DatasourceManager', selectedDataSource); + const OAuthDs = ['slack', 'zendesk', 'googlesheets', 'salesforce']; const name = selectedDataSource.name; const kind = selectedDataSource.kind; const pluginId = selectedDataSourcePluginId; diff --git a/frontend/src/_components/DynamicForm.jsx b/frontend/src/_components/DynamicForm.jsx index 0b5190d136..f95bd7ee05 100644 --- a/frontend/src/_components/DynamicForm.jsx +++ b/frontend/src/_components/DynamicForm.jsx @@ -155,6 +155,8 @@ const DynamicForm = ({ return OpenApi; case 'react-component-zendesk': return Zendesk; + case 'react-component-salesforce': + return Salesforce; default: return
Type is invalid
; } diff --git a/frontend/src/_components/Salesforce.jsx b/frontend/src/_components/Salesforce.jsx index 0d8630a78f..8f60eba347 100644 --- a/frontend/src/_components/Salesforce.jsx +++ b/frontend/src/_components/Salesforce.jsx @@ -15,7 +15,7 @@ const Salesforce = ({ optionchanged, createDataSource, options, isSaving, select { value: 'v2', label: 'v2' }, ]; function authSalesforce() { - const provider = selectedDataSource?.kind; + const provider = 'salesforce'; const plugin_id = selectedDataSource?.plugin?.id; const source_options = options; setAuthStatus('waiting_for_url'); @@ -24,26 +24,39 @@ const Salesforce = ({ optionchanged, createDataSource, options, isSaving, select .fetchOauth2BaseUrl(provider, plugin_id, source_options) .then((data) => { console.log('options', source_options); - console.log('data from Oauth', data); + console.log('data from Oauth', data.url); + console.log('selectedDataSource.kind', selectedDataSource.kind); + localStorage.setItem('sourceWaitingForOAuth', 'newSource'); + optionchanged('provider', provider).then(() => { + optionchanged('oauth2', true); + optionchanged('plugin_id', plugin_id); + }); + setAuthStatus('waiting_for_token'); + window.open(data.url); }) .catch(({ error }) => { toast.error(error); setAuthStatus(null); }); } + function saveDataSource() { + console.log('selectedDS', selectedDataSource); + optionchanged('code', localStorage.getItem('OAuthCode')).then(() => { + createDataSource(); + }); + } return (
- + + value={options?.api_version?.value} + onChange={(value) => optionchanged('api_version', value)} + width={'100%'} + useMenuPortal={false} + />
@@ -65,6 +78,7 @@ const Salesforce = ({ optionchanged, createDataSource, options, isSaving, select value={options?.client_secret?.value ?? ''} placeholder="Client Secret" workspaceConstants={workspaceConstants} + encrypted={true} />
@@ -79,7 +93,27 @@ const Salesforce = ({ optionchanged, createDataSource, options, isSaving, select
- + {authStatus === 'waiting_for_token' && ( +
+ +
+ )} + + {(!authStatus || authStatus === 'waiting_for_url') && ( + + )}
diff --git a/marketplace/package-lock.json b/marketplace/package-lock.json index c389f31945..6914151c8e 100644 --- a/marketplace/package-lock.json +++ b/marketplace/package-lock.json @@ -6737,6 +6737,73 @@ "node": ">=14.0.0" } }, + "node_modules/@supabase/auth-js": { + "version": "2.63.0", + "resolved": "https://registry.npmjs.org/@supabase/auth-js/-/auth-js-2.63.0.tgz", + "integrity": "sha512-yIgcHnlgv24GxHtVGUhwGqAFDyJkPIC/xjx7HostN08A8yCy8HIfl4JEkTKyBqD1v1L05jNEJOUke4Lf4O1+Qg==", + "dependencies": { + "@supabase/node-fetch": "^2.6.14" + } + }, + "node_modules/@supabase/functions-js": { + "version": "2.2.2", + "resolved": "https://registry.npmjs.org/@supabase/functions-js/-/functions-js-2.2.2.tgz", + "integrity": "sha512-sJGq1nludmi7pY/fdtCpyY/pYonx7MfHdN408bqb736guWcVI1AChYVbI4kUM978EuOE4Ci6l7bUudfGg07QRw==", + "dependencies": { + "@supabase/node-fetch": "^2.6.14" + } + }, + "node_modules/@supabase/node-fetch": { + "version": "2.6.15", + "resolved": "https://registry.npmjs.org/@supabase/node-fetch/-/node-fetch-2.6.15.tgz", + "integrity": "sha512-1ibVeYUacxWYi9i0cf5efil6adJ9WRyZBLivgjs+AUpewx1F3xPi7gLgaASI2SmIQxPoCEjAsLAzKPgMJVgOUQ==", + "dependencies": { + "whatwg-url": "^5.0.0" + }, + "engines": { + "node": "4.x || >=6.0.0" + } + }, + "node_modules/@supabase/postgrest-js": { + "version": "1.15.0", + "resolved": "https://registry.npmjs.org/@supabase/postgrest-js/-/postgrest-js-1.15.0.tgz", + "integrity": "sha512-U4bwBOrhsXWqDjZiYNbVqMBtRGgIIYE0kE5ZNSwsIbeBWfr/UxOMrnkIQUBGIZRhpYW/tw1WnTdRl1AGNyaxcw==", + "dependencies": { + "@supabase/node-fetch": "^2.6.14" + } + }, + "node_modules/@supabase/realtime-js": { + "version": "2.9.3", + "resolved": "https://registry.npmjs.org/@supabase/realtime-js/-/realtime-js-2.9.3.tgz", + "integrity": "sha512-lAp50s2n3FhGJFq+wTSXLNIDPw5Y0Wxrgt44eM5nLSA3jZNUUP3Oq2Ccd1CbZdVntPCWLZvJaU//pAd2NE+QnQ==", + "dependencies": { + "@supabase/node-fetch": "^2.6.14", + "@types/phoenix": "^1.5.4", + "@types/ws": "^8.5.10", + "ws": "^8.14.2" + } + }, + "node_modules/@supabase/storage-js": { + "version": "2.5.5", + "resolved": "https://registry.npmjs.org/@supabase/storage-js/-/storage-js-2.5.5.tgz", + "integrity": "sha512-OpLoDRjFwClwc2cjTJZG8XviTiQH4Ik8sCiMK5v7et0MDu2QlXjCAW3ljxJB5+z/KazdMOTnySi+hysxWUPu3w==", + "dependencies": { + "@supabase/node-fetch": "^2.6.14" + } + }, + "node_modules/@supabase/supabase-js": { + "version": "2.42.0", + "resolved": "https://registry.npmjs.org/@supabase/supabase-js/-/supabase-js-2.42.0.tgz", + "integrity": "sha512-1PDqJiA4iG45w3AAu6xkccJ3wPqlGJUoz9CPhScRLLTStxhewYhz0mjryTpXz1kgtNHdUAsirALreezn8UZMjA==", + "dependencies": { + "@supabase/auth-js": "2.63.0", + "@supabase/functions-js": "2.2.2", + "@supabase/node-fetch": "2.6.15", + "@supabase/postgrest-js": "1.15.0", + "@supabase/realtime-js": "2.9.3", + "@supabase/storage-js": "2.5.5" + } + }, "node_modules/@tooljet-marketplace/awsredshift": { "resolved": "plugins/awsredshift", "link": true @@ -6765,6 +6832,10 @@ "resolved": "plugins/plivo", "link": true }, + "node_modules/@tooljet-marketplace/pocketbase": { + "resolved": "plugins/pocketbase", + "link": true + }, "node_modules/@tooljet-marketplace/s3": { "resolved": "plugins/s3", "link": true @@ -6773,6 +6844,10 @@ "resolved": "plugins/salesforce", "link": true }, + "node_modules/@tooljet-marketplace/supabase": { + "resolved": "plugins/supabase", + "link": true + }, "node_modules/@tooljet-marketplace/textract": { "resolved": "plugins/textract", "link": true @@ -6954,6 +7029,11 @@ "dev": true, "license": "MIT" }, + "node_modules/@types/phoenix": { + "version": "1.6.4", + "resolved": "https://registry.npmjs.org/@types/phoenix/-/phoenix-1.6.4.tgz", + "integrity": "sha512-B34A7uot1Cv0XtaHRYDATltAdKx0BvVKNgYNqE4WjtPUa4VQJM7kxeXcVKaH+KS+kCmZ+6w+QaUdcljiheiBJA==" + }, "node_modules/@types/prettier": { "version": "2.7.2", "dev": true, @@ -6970,6 +7050,14 @@ "dev": true, "license": "MIT" }, + "node_modules/@types/ws": { + "version": "8.5.10", + "resolved": "https://registry.npmjs.org/@types/ws/-/ws-8.5.10.tgz", + "integrity": "sha512-vmQSUcfalpIq0R9q7uTo2lXs6eGIpt9wtnLdMv9LVpIjCA/+ufZRozlVoVelIYixx1ugCBKDhn89vnsEGOCx9A==", + "dependencies": { + "@types/node": "*" + } + }, "node_modules/@types/yargs": { "version": "17.0.24", "dev": true, @@ -14708,6 +14796,11 @@ "xmlbuilder": "^9.0.1" } }, + "node_modules/pocketbase": { + "version": "0.21.1", + "resolved": "https://registry.npmjs.org/pocketbase/-/pocketbase-0.21.1.tgz", + "integrity": "sha512-0PvCP4pKtxsV9kwldEGyibEvhwOcx9jSCrz3WN5CgPILJfM0z76f1op9WE8/8UgikDsMdRsc5iBLfKintrJS1g==" + }, "node_modules/postcss-selector-parser": { "version": "6.0.11", "dev": true, @@ -16849,6 +16942,26 @@ "node": ">=6" } }, + "node_modules/ws": { + "version": "8.16.0", + "resolved": "https://registry.npmjs.org/ws/-/ws-8.16.0.tgz", + "integrity": "sha512-HS0c//TP7Ina87TfiPUz1rQzMhHrl/SG2guqRcTOIUYD2q8uhUdNHZYJUaQ8aTGPzCh+c6oawMKW35nFl1dxyQ==", + "engines": { + "node": ">=10.0.0" + }, + "peerDependencies": { + "bufferutil": "^4.0.1", + "utf-8-validate": ">=5.0.2" + }, + "peerDependenciesMeta": { + "bufferutil": { + "optional": true + }, + "utf-8-validate": { + "optional": true + } + } + }, "node_modules/xml2js": { "version": "0.4.19", "license": "MIT", @@ -16958,6 +17071,7 @@ } }, "plugins/engagespot": { + "name": "@tooljet-marketplace/engagespot", "version": "1.0.0", "dependencies": { "@engagespot/node": "^1.5.1", @@ -17016,6 +17130,17 @@ "typescript": "^4.7.4" } }, + "plugins/pocketbase": { + "version": "1.0.0", + "dependencies": { + "@tooljet-marketplace/common": "^1.0.0", + "pocketbase": "^0.21.1" + }, + "devDependencies": { + "@vercel/ncc": "^0.34.0", + "typescript": "^4.7.4" + } + }, "plugins/s3": { "name": "@tooljet-marketplace/s3", "version": "1.0.0", @@ -17030,6 +17155,7 @@ } }, "plugins/salesforce": { + "name": "@tooljet-marketplace/salesforce", "version": "1.0.0", "dependencies": { "@tooljet-marketplace/common": "^1.0.0", @@ -17040,6 +17166,17 @@ "typescript": "^4.7.4" } }, + "plugins/supabase": { + "version": "1.0.0", + "dependencies": { + "@supabase/supabase-js": "^2.41.1", + "@tooljet-marketplace/common": "^1.0.0" + }, + "devDependencies": { + "@vercel/ncc": "^0.34.0", + "typescript": "^4.7.4" + } + }, "plugins/textract": { "name": "@tooljet-marketplace/textract", "version": "1.0.0", @@ -21935,6 +22072,70 @@ "tslib": "^2.5.0" } }, + "@supabase/auth-js": { + "version": "2.63.0", + "resolved": "https://registry.npmjs.org/@supabase/auth-js/-/auth-js-2.63.0.tgz", + "integrity": "sha512-yIgcHnlgv24GxHtVGUhwGqAFDyJkPIC/xjx7HostN08A8yCy8HIfl4JEkTKyBqD1v1L05jNEJOUke4Lf4O1+Qg==", + "requires": { + "@supabase/node-fetch": "^2.6.14" + } + }, + "@supabase/functions-js": { + "version": "2.2.2", + "resolved": "https://registry.npmjs.org/@supabase/functions-js/-/functions-js-2.2.2.tgz", + "integrity": "sha512-sJGq1nludmi7pY/fdtCpyY/pYonx7MfHdN408bqb736guWcVI1AChYVbI4kUM978EuOE4Ci6l7bUudfGg07QRw==", + "requires": { + "@supabase/node-fetch": "^2.6.14" + } + }, + "@supabase/node-fetch": { + "version": "2.6.15", + "resolved": "https://registry.npmjs.org/@supabase/node-fetch/-/node-fetch-2.6.15.tgz", + "integrity": "sha512-1ibVeYUacxWYi9i0cf5efil6adJ9WRyZBLivgjs+AUpewx1F3xPi7gLgaASI2SmIQxPoCEjAsLAzKPgMJVgOUQ==", + "requires": { + "whatwg-url": "^5.0.0" + } + }, + "@supabase/postgrest-js": { + "version": "1.15.0", + "resolved": "https://registry.npmjs.org/@supabase/postgrest-js/-/postgrest-js-1.15.0.tgz", + "integrity": "sha512-U4bwBOrhsXWqDjZiYNbVqMBtRGgIIYE0kE5ZNSwsIbeBWfr/UxOMrnkIQUBGIZRhpYW/tw1WnTdRl1AGNyaxcw==", + "requires": { + "@supabase/node-fetch": "^2.6.14" + } + }, + "@supabase/realtime-js": { + "version": "2.9.3", + "resolved": "https://registry.npmjs.org/@supabase/realtime-js/-/realtime-js-2.9.3.tgz", + "integrity": "sha512-lAp50s2n3FhGJFq+wTSXLNIDPw5Y0Wxrgt44eM5nLSA3jZNUUP3Oq2Ccd1CbZdVntPCWLZvJaU//pAd2NE+QnQ==", + "requires": { + "@supabase/node-fetch": "^2.6.14", + "@types/phoenix": "^1.5.4", + "@types/ws": "^8.5.10", + "ws": "^8.14.2" + } + }, + "@supabase/storage-js": { + "version": "2.5.5", + "resolved": "https://registry.npmjs.org/@supabase/storage-js/-/storage-js-2.5.5.tgz", + "integrity": "sha512-OpLoDRjFwClwc2cjTJZG8XviTiQH4Ik8sCiMK5v7et0MDu2QlXjCAW3ljxJB5+z/KazdMOTnySi+hysxWUPu3w==", + "requires": { + "@supabase/node-fetch": "^2.6.14" + } + }, + "@supabase/supabase-js": { + "version": "2.42.0", + "resolved": "https://registry.npmjs.org/@supabase/supabase-js/-/supabase-js-2.42.0.tgz", + "integrity": "sha512-1PDqJiA4iG45w3AAu6xkccJ3wPqlGJUoz9CPhScRLLTStxhewYhz0mjryTpXz1kgtNHdUAsirALreezn8UZMjA==", + "requires": { + "@supabase/auth-js": "2.63.0", + "@supabase/functions-js": "2.2.2", + "@supabase/node-fetch": "2.6.15", + "@supabase/postgrest-js": "1.15.0", + "@supabase/realtime-js": "2.9.3", + "@supabase/storage-js": "2.5.5" + } + }, "@tooljet-marketplace/awsredshift": { "version": "file:plugins/awsredshift", "requires": { @@ -21994,6 +22195,15 @@ "typescript": "^4.7.4" } }, + "@tooljet-marketplace/pocketbase": { + "version": "file:plugins/pocketbase", + "requires": { + "@tooljet-marketplace/common": "^1.0.0", + "@vercel/ncc": "^0.34.0", + "pocketbase": "^0.21.1", + "typescript": "^4.7.4" + } + }, "@tooljet-marketplace/s3": { "version": "file:plugins/s3", "requires": { @@ -22013,6 +22223,15 @@ "typescript": "^4.7.4" } }, + "@tooljet-marketplace/supabase": { + "version": "file:plugins/supabase", + "requires": { + "@supabase/supabase-js": "^2.41.1", + "@tooljet-marketplace/common": "^1.0.0", + "@vercel/ncc": "^0.34.0", + "typescript": "^4.7.4" + } + }, "@tooljet-marketplace/textract": { "version": "file:plugins/textract", "requires": { @@ -22174,6 +22393,11 @@ "version": "4.0.0", "dev": true }, + "@types/phoenix": { + "version": "1.6.4", + "resolved": "https://registry.npmjs.org/@types/phoenix/-/phoenix-1.6.4.tgz", + "integrity": "sha512-B34A7uot1Cv0XtaHRYDATltAdKx0BvVKNgYNqE4WjtPUa4VQJM7kxeXcVKaH+KS+kCmZ+6w+QaUdcljiheiBJA==" + }, "@types/prettier": { "version": "2.7.2", "dev": true, @@ -22187,6 +22411,14 @@ "version": "2.0.1", "dev": true }, + "@types/ws": { + "version": "8.5.10", + "resolved": "https://registry.npmjs.org/@types/ws/-/ws-8.5.10.tgz", + "integrity": "sha512-vmQSUcfalpIq0R9q7uTo2lXs6eGIpt9wtnLdMv9LVpIjCA/+ufZRozlVoVelIYixx1ugCBKDhn89vnsEGOCx9A==", + "requires": { + "@types/node": "*" + } + }, "@types/yargs": { "version": "17.0.24", "dev": true, @@ -27222,6 +27454,11 @@ "xmlbuilder": "^9.0.1" } }, + "pocketbase": { + "version": "0.21.1", + "resolved": "https://registry.npmjs.org/pocketbase/-/pocketbase-0.21.1.tgz", + "integrity": "sha512-0PvCP4pKtxsV9kwldEGyibEvhwOcx9jSCrz3WN5CgPILJfM0z76f1op9WE8/8UgikDsMdRsc5iBLfKintrJS1g==" + }, "postcss-selector-parser": { "version": "6.0.11", "dev": true, @@ -28586,6 +28823,12 @@ } } }, + "ws": { + "version": "8.16.0", + "resolved": "https://registry.npmjs.org/ws/-/ws-8.16.0.tgz", + "integrity": "sha512-HS0c//TP7Ina87TfiPUz1rQzMhHrl/SG2guqRcTOIUYD2q8uhUdNHZYJUaQ8aTGPzCh+c6oawMKW35nFl1dxyQ==", + "requires": {} + }, "xml2js": { "version": "0.4.19", "requires": { diff --git a/marketplace/plugins/salesforce/lib/index.ts b/marketplace/plugins/salesforce/lib/index.ts index a0ce2b319a..b1e318c192 100644 --- a/marketplace/plugins/salesforce/lib/index.ts +++ b/marketplace/plugins/salesforce/lib/index.ts @@ -18,6 +18,32 @@ export default class Salesforce implements QueryService { const fullUrl = `${host}${subpath ? subpath : '/'}`; const redirectUri = `${fullUrl}oauth2/authorize`; const client_secret = source_options.client_secret.value; - return `https://login.salesforce.com/services/oauth2/authorize?response_type=code&client_id=${client_id}&redirect_uri=${redirectUri}&state=YOUR_STATE`; + const oauth2 = new jsforce.OAuth2({ + clientId: client_id, + clientSecret: client_secret, + redirectUri: redirectUri, + }); + const authorizationUrl = oauth2.getAuthorizationUrl({ + scope: 'full', + }); + return authorizationUrl; + } + async accessDetailsFrom(authCode: string, source_options): Promise { + const client_id = source_options.client_id.value; + const host = process.env.TOOLJET_HOST; + const subpath = process.env.SUB_PATH; + const fullUrl = `${host}${subpath ? subpath : '/'}`; + const redirectUri = `${fullUrl}oauth2/authorize`; + const client_secret = source_options.client_secret.value; + const oauth2 = new jsforce.OAuth2({ + clientId: client_id, + clientSecret: client_secret, + redirectUri: redirectUri, + }); + const conn = new jsforce.Connection({ oauth2: oauth2 }); + const response = await conn.authorize(authCode); + const authDetails = []; + authDetails.push(['response', response]); + return authDetails; } } diff --git a/server/src/services/data_sources.service.ts b/server/src/services/data_sources.service.ts index 2a816af261..93e87228df 100644 --- a/server/src/services/data_sources.service.ts +++ b/server/src/services/data_sources.service.ts @@ -1,4 +1,3 @@ -import allPlugins from '@tooljet/plugins/dist/server'; import { Injectable, NotAcceptableException, NotImplementedException } from '@nestjs/common'; import { InjectRepository } from '@nestjs/typeorm'; import { EntityManager, getManager, Repository } from 'typeorm'; @@ -364,8 +363,10 @@ export class DataSourcesService { if (findOption(options, 'oauth2') && findOption(options, 'code')) { const provider = findOption(options, 'provider')['value']; const authCode = findOption(options, 'code')['value']; + const plugin_id = findOption(options, 'plugin_id')['value']; + const queryService = await this.pluginsHelper.getService(plugin_id, provider); - const queryService = new allPlugins[provider](); + //const queryService = new allPlugins[provider](); const accessDetails = await queryService.accessDetailsFrom(authCode, options); for (const row of accessDetails) {