Adding fallbacks for oidc and google.
This commit is contained in:
parent
853b7b6fdc
commit
f2e713f5af
|
@ -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"),
|
||||
},
|
||||
],
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@ const { StaticDatabases } = require("@budibase/auth/db")
|
|||
|
||||
exports.multiTenancyEnabled = async ctx => {
|
||||
ctx.body = {
|
||||
enabled: !!env.MULTI_TENANCY,
|
||||
enabled: false,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue