Adding fallbacks for oidc and google.
This commit is contained in:
parent
1b6a73c250
commit
b21fe320c5
|
@ -21,16 +21,26 @@
|
||||||
} from "@budibase/bbui"
|
} from "@budibase/bbui"
|
||||||
import { onMount } from "svelte"
|
import { onMount } from "svelte"
|
||||||
import api from "builderStore/api"
|
import api from "builderStore/api"
|
||||||
import { organisation, auth } from "stores/portal"
|
import { organisation, auth, admin } from "stores/portal"
|
||||||
import { uuid } from "builderStore/uuid"
|
import { uuid } from "builderStore/uuid"
|
||||||
|
|
||||||
$: tenantId = $auth.tenantId
|
$: tenantId = $auth.tenantId
|
||||||
|
$: multiTenancyEnabled = $admin.multiTenancy
|
||||||
|
|
||||||
const ConfigTypes = {
|
const ConfigTypes = {
|
||||||
Google: "google",
|
Google: "google",
|
||||||
OIDC: "oidc",
|
OIDC: "oidc",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function callbackUrl(tenantId, end) {
|
||||||
|
let url = `/api/global/auth`
|
||||||
|
if (multiTenancyEnabled && tenantId) {
|
||||||
|
url += `/${tenantId}`
|
||||||
|
}
|
||||||
|
url += end
|
||||||
|
return url
|
||||||
|
}
|
||||||
|
|
||||||
$: GoogleConfigFields = {
|
$: GoogleConfigFields = {
|
||||||
Google: [
|
Google: [
|
||||||
{ name: "clientID", label: "Client ID" },
|
{ name: "clientID", label: "Client ID" },
|
||||||
|
@ -39,7 +49,7 @@
|
||||||
name: "callbackURL",
|
name: "callbackURL",
|
||||||
label: "Callback URL",
|
label: "Callback URL",
|
||||||
readonly: true,
|
readonly: true,
|
||||||
placeholder: `/api/global/auth/${tenantId}/google/callback`,
|
placeholder: callbackUrl(tenantId, "/google/callback"),
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
}
|
}
|
||||||
|
@ -53,7 +63,7 @@
|
||||||
name: "callbackURL",
|
name: "callbackURL",
|
||||||
label: "Callback URL",
|
label: "Callback URL",
|
||||||
readonly: true,
|
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 { checkResetPasswordCode } = require("../../../utilities/redis")
|
||||||
const { getGlobalDB } = authPkg.db
|
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) {
|
async function authInternal(ctx, user, err = null, info = null) {
|
||||||
if (err) {
|
if (err) {
|
||||||
console.error("Authentication error", 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.
|
* On a successful login, you will be redirected to the googleAuth callback route.
|
||||||
*/
|
*/
|
||||||
exports.googlePreAuth = async (ctx, next) => {
|
exports.googlePreAuth = async (ctx, next) => {
|
||||||
const tenantId = ctx.params.tenantId
|
const tenantId = ctx.params ? ctx.params.tenantId : null
|
||||||
const db = getGlobalDB(tenantId)
|
const db = getGlobalDB(tenantId)
|
||||||
const callbackUrl = `/api/global/auth/${tenantId}/google/callback`
|
let callbackUrl = googleCallbackUrl(tenantId)
|
||||||
|
|
||||||
const config = await authPkg.db.getScopedConfig(db, {
|
const config = await authPkg.db.getScopedConfig(db, {
|
||||||
type: Configs.GOOGLE,
|
type: Configs.GOOGLE,
|
||||||
|
@ -117,9 +126,9 @@ exports.googlePreAuth = async (ctx, next) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.googleAuth = 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 db = getGlobalDB(tenantId)
|
||||||
const callbackUrl = `/api/global/auth/${tenantId}/google/callback`
|
const callbackUrl = googleCallbackUrl(tenantId)
|
||||||
|
|
||||||
const config = await authPkg.db.getScopedConfig(db, {
|
const config = await authPkg.db.getScopedConfig(db, {
|
||||||
type: Configs.GOOGLE,
|
type: Configs.GOOGLE,
|
||||||
|
@ -139,7 +148,7 @@ exports.googleAuth = async (ctx, next) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
async function oidcStrategyFactory(ctx, configId) {
|
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 db = getGlobalDB(ctx.params.tenantId)
|
||||||
const config = await authPkg.db.getScopedConfig(db, {
|
const config = await authPkg.db.getScopedConfig(db, {
|
||||||
type: Configs.OIDC,
|
type: Configs.OIDC,
|
||||||
|
@ -148,8 +157,11 @@ async function oidcStrategyFactory(ctx, configId) {
|
||||||
|
|
||||||
const chosenConfig = config.configs.filter(c => c.uuid === configId)[0]
|
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)
|
return oidc.strategyFactory(chosenConfig, callbackUrl)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,7 @@ const { StaticDatabases } = require("@budibase/auth/db")
|
||||||
|
|
||||||
exports.multiTenancyEnabled = async ctx => {
|
exports.multiTenancyEnabled = async ctx => {
|
||||||
ctx.body = {
|
ctx.body = {
|
||||||
enabled: !!env.MULTI_TENANCY,
|
enabled: false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -52,5 +52,13 @@ router
|
||||||
authController.oidcPreAuth
|
authController.oidcPreAuth
|
||||||
)
|
)
|
||||||
.get("/api/global/auth/:tenantId/oidc/callback", authController.oidcAuth)
|
.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
|
module.exports = router
|
||||||
|
|
Loading…
Reference in New Issue