From 29007435455ecdf8d3e68969ceb09182914d9cb4 Mon Sep 17 00:00:00 2001 From: Peter Clement Date: Tue, 13 Jul 2021 15:52:21 +0100 Subject: [PATCH] Add UUID to each oidc config to distinguish each provider --- .../middleware/passport/tests/utilities.js | 25 ++++++++++++------- .../builder/portal/manage/auth/index.svelte | 10 +++++++- packages/builder/src/stores/portal/oidc.js | 1 + .../src/api/controllers/admin/configs.js | 1 + .../worker/src/api/routes/admin/configs.js | 3 ++- 5 files changed, 29 insertions(+), 11 deletions(-) diff --git a/packages/auth/src/middleware/passport/tests/utilities.js b/packages/auth/src/middleware/passport/tests/utilities.js index 69e8312915..df71c82663 100644 --- a/packages/auth/src/middleware/passport/tests/utilities.js +++ b/packages/auth/src/middleware/passport/tests/utilities.js @@ -7,14 +7,21 @@ const mockEmail = "mock@budibase.com" const mockAccessToken = "mockAccessToken" const mockRefreshToken = "mockRefreshToken" -const buildOauth2 = (accessToken=mockAccessToken, refreshToken=mockRefreshToken) => ( - { - accessToken: accessToken, - refreshToken: refreshToken, - } -) +const buildOauth2 = ( + accessToken = mockAccessToken, + refreshToken = mockRefreshToken +) => ({ + accessToken: accessToken, + refreshToken: refreshToken, +}) -const buildThirdPartyUser = (provider, providerType, profile, email=mockEmail, oauth2=buildOauth2()) => ({ +const buildThirdPartyUser = ( + provider, + providerType, + profile, + email = mockEmail, + oauth2 = buildOauth2() +) => ({ provider: provider, providerType: providerType, userId: profile.id, @@ -29,5 +36,5 @@ exports.data = { email: mockEmail, accessToken: mockAccessToken, refreshToken: mockRefreshToken, - buildThirdPartyUser -} \ No newline at end of file + buildThirdPartyUser, +} diff --git a/packages/builder/src/pages/builder/portal/manage/auth/index.svelte b/packages/builder/src/pages/builder/portal/manage/auth/index.svelte index 9c91974177..1dde7a673d 100644 --- a/packages/builder/src/pages/builder/portal/manage/auth/index.svelte +++ b/packages/builder/src/pages/builder/portal/manage/auth/index.svelte @@ -19,6 +19,7 @@ import { onMount } from "svelte" import api from "builderStore/api" import { organisation } from "stores/portal" + import { uuid } from "builderStore/uuid" const ConfigTypes = { Google: "google", @@ -87,10 +88,17 @@ const providers = { google, oidc } async function save(docs) { + console.log(docs) // only if the user has provided an image, upload it. image && uploadLogo(image) let calls = [] docs.forEach(element => { + //Add a UUID here so each config is distinguishable when it arrives at the login page. + if (element.type === "oidc") { + element.config.configs.forEach(config => { + config.uuid = uuid() + }) + } calls.push(api.post(`/api/admin/configs`, element)) }) Promise.all(calls) @@ -184,7 +192,7 @@ To allow users to authenticate using their Google accounts, fill out the fields below. - dddd + {#each GoogleConfigFields.Google as field}
diff --git a/packages/builder/src/stores/portal/oidc.js b/packages/builder/src/stores/portal/oidc.js index e482bcae5a..d8d06f12a9 100644 --- a/packages/builder/src/stores/portal/oidc.js +++ b/packages/builder/src/stores/portal/oidc.js @@ -4,6 +4,7 @@ import api from "builderStore/api" const OIDC_CONFIG = { logo: undefined, name: undefined, + uuid: undefined, } export function createOidcStore() { diff --git a/packages/worker/src/api/controllers/admin/configs.js b/packages/worker/src/api/controllers/admin/configs.js index ceda7b6342..0dbfb50159 100644 --- a/packages/worker/src/api/controllers/admin/configs.js +++ b/packages/worker/src/api/controllers/admin/configs.js @@ -113,6 +113,7 @@ exports.publicOidc = async function (ctx) { return { logo: config.logo, name: config.name, + uuid: config.uuid, } }) ctx.body = partialOidcCofig diff --git a/packages/worker/src/api/routes/admin/configs.js b/packages/worker/src/api/routes/admin/configs.js index 12af793068..fd7764316b 100644 --- a/packages/worker/src/api/routes/admin/configs.js +++ b/packages/worker/src/api/routes/admin/configs.js @@ -50,7 +50,8 @@ function oidcValidation() { clientSecret: Joi.string().required(), configUrl: Joi.string().required(), logo: Joi.string().optional(), - name: Joi.string().optional(), + name: Joi.string().optional(), + uuid: Joi.string().required(), }) ).required(true) }).unknown(true)