Browse Source

add new logic to support oauth and oidc buttons

pull/1920/head
Peter Clement 5 years ago
parent
commit
4e75b7f4c9
  1. 7
      packages/builder/src/pages/builder/auth/_components/GoogleButton.svelte
  2. 5
      packages/builder/src/pages/builder/auth/_components/OIDCButton.svelte
  3. 4
      packages/builder/src/stores/portal/organisation.js
  4. 22
      packages/worker/src/api/controllers/admin/configs.js

7
packages/builder/src/pages/builder/auth/_components/GoogleButton.svelte

@ -1,11 +1,10 @@
<script>
import { ActionButton } from "@budibase/bbui"
import GoogleLogo from "assets/google-logo.png"
import { admin } from "stores/portal"
import { organisation } from "stores/portal"
let show = false
$: show = $admin.checklist?.oauth
$: show = $organisation.google
console.log(show)
</script>
{#if show}

5
packages/builder/src/pages/builder/auth/_components/OIDCButton.svelte

@ -4,10 +4,10 @@
import Auth0Logo from "assets/auth0-logo.png"
import MicrosoftLogo from "assets/microsoft-logo.png"
import { admin, oidc } from "stores/portal"
import { oidc, organisation } from "stores/portal"
import { onMount } from "svelte"
let show = false
$: show = $organisation.oidc
let preDefinedIcons = {
Oidc: OidcLogo,
@ -19,7 +19,6 @@
await oidc.init()
})
$: show = $admin.checklist?.oidc
$: src = !$oidc.logo
? OidcLogo
: preDefinedIcons[$oidc.logo] || `/global/logos_oidc/${$oidc.logo}`

4
packages/builder/src/stores/portal/organisation.js

@ -6,6 +6,8 @@ const DEFAULT_CONFIG = {
logoUrl: undefined,
docsUrl: undefined,
company: "Budibase",
oidc: undefined,
google: undefined,
}
export function createOrganisationStore() {
@ -15,7 +17,7 @@ export function createOrganisationStore() {
async function init() {
const res = await api.get(`/api/admin/configs/public`)
const json = await res.json()
console.log(json)
if (json.status === 400) {
set(DEFAULT_CONFIG)
} else {

22
packages/worker/src/api/controllers/admin/configs.js

@ -125,16 +125,34 @@ exports.publicOidc = async function (ctx) {
exports.publicSettings = async function (ctx) {
const db = new CouchDB(GLOBAL_DB)
let config = {}
try {
// Find the config with the most granular scope based on context
const publicConfig = await getScopedFullConfig(db, {
type: Configs.SETTINGS,
})
if (!publicConfig) {
const googleConfig = await getScopedFullConfig(db, {
type: Configs.GOOGLE,
})
const oidcConfig = await getScopedFullConfig(db, {
type: Configs.OIDC,
})
// Slightly complex logic here to deal with the fact that
// oidc / google might be enabled but org name etc (publicConfig) might not
if (publicConfig && !!googleConfig && !!oidcConfig) {
ctx.body = publicConfig
} else if (!publicConfig && !!googleConfig && !!oidcConfig) {
ctx.body = {}
} else {
ctx.body = publicConfig
if (publicConfig) {
config.config = publicConfig.config
}
config.config.oidc = !!oidcConfig
config.config.google = !!googleConfig
ctx.body = config
}
} catch (err) {
ctx.throw(err.status, err)

Loading…
Cancel
Save