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 bcbdfe6460..2ca0f7e2e8 100644 --- a/packages/builder/src/pages/builder/portal/manage/auth/index.svelte +++ b/packages/builder/src/pages/builder/portal/manage/auth/index.svelte @@ -21,16 +21,26 @@ } from "@budibase/bbui" import { onMount } from "svelte" import api from "builderStore/api" - import { organisation, auth } from "stores/portal" + import { organisation, auth, admin } from "stores/portal" import { uuid } from "builderStore/uuid" $: tenantId = $auth.tenantId + $: multiTenancyEnabled = $admin.multiTenancy const ConfigTypes = { Google: "google", OIDC: "oidc", } + function callbackUrl(tenantId, end) { + let url = `/api/global/auth` + if (multiTenancyEnabled && tenantId) { + url += `/${tenantId}` + } + url += end + return url + } + $: GoogleConfigFields = { Google: [ { name: "clientID", label: "Client ID" }, @@ -39,7 +49,7 @@ name: "callbackURL", label: "Callback URL", readonly: true, - placeholder: `/api/global/auth/${tenantId}/google/callback`, + placeholder: callbackUrl(tenantId, "/google/callback"), }, ], } @@ -53,7 +63,7 @@ name: "callbackURL", label: "Callback URL", readonly: true, - placeholder: `/api/global/auth/${tenantId}/oidc/callback`, + placeholder: callbackUrl(tenantId, "/oidc/callback"), }, ], } diff --git a/packages/worker/src/api/controllers/global/auth.js b/packages/worker/src/api/controllers/global/auth.js index 82faea986f..c3bbaf41a2 100644 --- a/packages/worker/src/api/controllers/global/auth.js +++ b/packages/worker/src/api/controllers/global/auth.js @@ -10,6 +10,15 @@ const { passport } = authPkg.auth const { checkResetPasswordCode } = require("../../../utilities/redis") const { getGlobalDB } = authPkg.db +function googleCallbackUrl(tenantId = null) { + let callbackUrl = `/api/global/auth` + if (tenantId) { + callbackUrl += `/${tenantId}` + } + callbackUrl += `/google/callback` + return callbackUrl +} + async function authInternal(ctx, user, err = null, info = null) { if (err) { console.error("Authentication error", err) @@ -101,9 +110,9 @@ exports.logout = async ctx => { * On a successful login, you will be redirected to the googleAuth callback route. */ exports.googlePreAuth = async (ctx, next) => { - const tenantId = ctx.params.tenantId + const tenantId = ctx.params ? ctx.params.tenantId : null const db = getGlobalDB(tenantId) - const callbackUrl = `/api/global/auth/${tenantId}/google/callback` + let callbackUrl = googleCallbackUrl(tenantId) const config = await authPkg.db.getScopedConfig(db, { type: Configs.GOOGLE, @@ -117,9 +126,9 @@ exports.googlePreAuth = async (ctx, next) => { } exports.googleAuth = async (ctx, next) => { - const tenantId = ctx.params.tenantId + const tenantId = ctx.params ? ctx.params.tenantId : null const db = getGlobalDB(tenantId) - const callbackUrl = `/api/global/auth/${tenantId}/google/callback` + const callbackUrl = googleCallbackUrl(tenantId) const config = await authPkg.db.getScopedConfig(db, { type: Configs.GOOGLE, @@ -139,7 +148,7 @@ exports.googleAuth = async (ctx, next) => { } async function oidcStrategyFactory(ctx, configId) { - const tenantId = ctx.params.tenantId + const tenantId = ctx.params ? ctx.params.tenantId : null const db = getGlobalDB(ctx.params.tenantId) const config = await authPkg.db.getScopedConfig(db, { type: Configs.OIDC, @@ -148,8 +157,11 @@ async function oidcStrategyFactory(ctx, configId) { const chosenConfig = config.configs.filter(c => c.uuid === configId)[0] - const callbackUrl = `${ctx.protocol}://${ctx.host}/api/global/auth/${tenantId}/oidc/callback` - + let callbackUrl = `${ctx.protocol}://${ctx.host}/api/global/auth` + if (tenantId) { + callbackUrl += `/${tenantId}` + } + callbackUrl += `/oidc/callback` return oidc.strategyFactory(chosenConfig, callbackUrl) } diff --git a/packages/worker/src/api/controllers/global/tenants.js b/packages/worker/src/api/controllers/global/tenants.js index ddf8930ddc..677ba5a20f 100644 --- a/packages/worker/src/api/controllers/global/tenants.js +++ b/packages/worker/src/api/controllers/global/tenants.js @@ -4,7 +4,7 @@ const { StaticDatabases } = require("@budibase/auth/db") exports.multiTenancyEnabled = async ctx => { ctx.body = { - enabled: !!env.MULTI_TENANCY, + enabled: false, } } diff --git a/packages/worker/src/api/routes/global/auth.js b/packages/worker/src/api/routes/global/auth.js index b7b560cb6c..19a61df2e3 100644 --- a/packages/worker/src/api/routes/global/auth.js +++ b/packages/worker/src/api/routes/global/auth.js @@ -52,5 +52,13 @@ router authController.oidcPreAuth ) .get("/api/global/auth/:tenantId/oidc/callback", authController.oidcAuth) + // deprecated - used by the default system before tenancy + .get("/api/global/auth/google", authController.googlePreAuth) + .get("/api/global/auth/google/callback", authController.googleAuth) + .get( + "/api/global/auth/oidc/configs/:configId", + authController.oidcPreAuth + ) + .get("/api/global/auth/oidc/callback", authController.oidcAuth) module.exports = router