From c2d97b94490406d1bd0324acc4e079cfe532f7a9 Mon Sep 17 00:00:00 2001 From: Martin McKeaveney Date: Thu, 6 Jan 2022 08:08:54 +0000 Subject: [PATCH] google auth working --- .../auth/src/middleware/passport/google.js | 1 + .../_components/GoogleButton.svelte | 44 +++++++++++ .../modals/CreateDatasourceModal.svelte | 1 + .../modals/DatasourceConfigModal.svelte | 17 +++-- packages/server/package.json | 1 + packages/server/src/constants/index.js | 4 + packages/server/src/definitions/datasource.ts | 2 + packages/server/src/environment.js | 2 + .../server/src/integrations/googlesheets.ts | 59 +++++++++------ packages/server/src/integrations/oracle.ts | 2 +- packages/server/yarn.lock | 59 +++++++++------ .../worker/src/api/controllers/global/auth.js | 75 +++++++++++++++++++ packages/worker/src/api/routes/global/auth.js | 7 ++ 13 files changed, 223 insertions(+), 51 deletions(-) create mode 100644 packages/builder/src/components/backend/DatasourceNavigator/_components/GoogleButton.svelte diff --git a/packages/auth/src/middleware/passport/google.js b/packages/auth/src/middleware/passport/google.js index cb93844c31..efe64d6337 100644 --- a/packages/auth/src/middleware/passport/google.js +++ b/packages/auth/src/middleware/passport/google.js @@ -46,6 +46,7 @@ exports.strategyFactory = async function ( clientID: config.clientID, clientSecret: config.clientSecret, callbackURL: callbackUrl, + store: true, }, verify ) diff --git a/packages/builder/src/components/backend/DatasourceNavigator/_components/GoogleButton.svelte b/packages/builder/src/components/backend/DatasourceNavigator/_components/GoogleButton.svelte new file mode 100644 index 0000000000..81b0d3370f --- /dev/null +++ b/packages/builder/src/components/backend/DatasourceNavigator/_components/GoogleButton.svelte @@ -0,0 +1,44 @@ + + + { + // TODO: can probably remove + const datasourceId = await preAuthStep() + window.open( + `/api/global/auth/${tenantId}/google2?datasourceId=${datasourceId}&appId=${$store.appId}`, + "_blank" + ) + }} +> +
+ google icon +

Sign in with Google

+
+
+ + diff --git a/packages/builder/src/components/backend/DatasourceNavigator/modals/CreateDatasourceModal.svelte b/packages/builder/src/components/backend/DatasourceNavigator/modals/CreateDatasourceModal.svelte index 1a433785dc..929f8e71c4 100644 --- a/packages/builder/src/components/backend/DatasourceNavigator/modals/CreateDatasourceModal.svelte +++ b/packages/builder/src/components/backend/DatasourceNavigator/modals/CreateDatasourceModal.svelte @@ -32,6 +32,7 @@ plus: selected.plus, config, schema: selected.datasource, + auth: selected.auth, } } diff --git a/packages/builder/src/components/backend/DatasourceNavigator/modals/DatasourceConfigModal.svelte b/packages/builder/src/components/backend/DatasourceNavigator/modals/DatasourceConfigModal.svelte index ffd908b101..819e2e1410 100644 --- a/packages/builder/src/components/backend/DatasourceNavigator/modals/DatasourceConfigModal.svelte +++ b/packages/builder/src/components/backend/DatasourceNavigator/modals/DatasourceConfigModal.svelte @@ -6,6 +6,7 @@ import { datasources, tables } from "stores/backend" import { IntegrationNames } from "constants" import cloneDeep from "lodash/cloneDeepWith" + import GoogleButton from "../_components/GoogleButton.svelte" export let integration export let modal @@ -33,11 +34,14 @@ return datasource } - async function saveDatasource() { + async function saveDatasource(fetchSchema) { const datasource = prepareData() try { // Create datasource - const resp = await datasources.save(datasource, datasource.plus) + const resp = await datasources.save( + datasource, + fetchSchema ?? datasource.plus + ) // update the tables incase data source plus await tables.fetch() @@ -48,7 +52,7 @@ name: resp.name, source: resp.source, }) - return true + return resp._id } catch (err) { notifications.error(`Error saving datasource: ${err}`) return false @@ -71,8 +75,11 @@ >Connect your database to Budibase using the config below. - - + {#if config.auth?.type === "google"} + saveDatasource(false)} /> + {:else} + + {/if}