|
|
@ -20,7 +20,7 @@ |
|
|
Toggle, |
|
|
Toggle, |
|
|
} from "@budibase/bbui" |
|
|
} from "@budibase/bbui" |
|
|
import { onMount } from "svelte" |
|
|
import { onMount } from "svelte" |
|
|
import api from "builderStore/api" |
|
|
import { API } from "api" |
|
|
import { organisation, admin } from "stores/portal" |
|
|
import { organisation, admin } from "stores/portal" |
|
|
import { Helpers } from "@budibase/bbui" |
|
|
import { Helpers } from "@budibase/bbui" |
|
|
import analytics, { Events } from "analytics" |
|
|
import analytics, { Events } from "analytics" |
|
|
@ -137,17 +137,6 @@ |
|
|
providers.oidc?.config?.configs[0].clientID && |
|
|
providers.oidc?.config?.configs[0].clientID && |
|
|
providers.oidc?.config?.configs[0].clientSecret |
|
|
providers.oidc?.config?.configs[0].clientSecret |
|
|
|
|
|
|
|
|
async function uploadLogo(file) { |
|
|
|
|
|
let data = new FormData() |
|
|
|
|
|
data.append("file", file) |
|
|
|
|
|
const res = await api.post( |
|
|
|
|
|
`/api/global/configs/upload/logos_oidc/${file.name}`, |
|
|
|
|
|
data, |
|
|
|
|
|
{} |
|
|
|
|
|
) |
|
|
|
|
|
return await res.json() |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const onFileSelected = e => { |
|
|
const onFileSelected = e => { |
|
|
let fileName = e.target.files[0].name |
|
|
let fileName = e.target.files[0].name |
|
|
image = e.target.files[0] |
|
|
image = e.target.files[0] |
|
|
@ -156,17 +145,28 @@ |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
async function save(docs) { |
|
|
async function save(docs) { |
|
|
// only if the user has provided an image, upload it. |
|
|
|
|
|
image && uploadLogo(image) |
|
|
|
|
|
let calls = [] |
|
|
let calls = [] |
|
|
|
|
|
|
|
|
|
|
|
// Only if the user has provided an image, upload it |
|
|
|
|
|
if (image) { |
|
|
|
|
|
let data = new FormData() |
|
|
|
|
|
data.append("file", image) |
|
|
|
|
|
calls.push( |
|
|
|
|
|
API.uploadOIDCLogo({ |
|
|
|
|
|
name: image.name, |
|
|
|
|
|
data, |
|
|
|
|
|
}) |
|
|
|
|
|
) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
docs.forEach(element => { |
|
|
docs.forEach(element => { |
|
|
if (element.type === ConfigTypes.OIDC) { |
|
|
if (element.type === ConfigTypes.OIDC) { |
|
|
//Add a UUID here so each config is distinguishable when it arrives at the login page |
|
|
// Add a UUID here so each config is distinguishable when it arrives at the login page |
|
|
for (let config of element.config.configs) { |
|
|
for (let config of element.config.configs) { |
|
|
if (!config.uuid) { |
|
|
if (!config.uuid) { |
|
|
config.uuid = Helpers.uuid() |
|
|
config.uuid = Helpers.uuid() |
|
|
} |
|
|
} |
|
|
// callback urls shouldn't be included |
|
|
// Callback urls shouldn't be included |
|
|
delete config.callbackURL |
|
|
delete config.callbackURL |
|
|
} |
|
|
} |
|
|
if (partialOidc) { |
|
|
if (partialOidc) { |
|
|
@ -175,8 +175,8 @@ |
|
|
`Please fill in all required ${ConfigTypes.OIDC} fields` |
|
|
`Please fill in all required ${ConfigTypes.OIDC} fields` |
|
|
) |
|
|
) |
|
|
} else { |
|
|
} else { |
|
|
calls.push(api.post(`/api/global/configs`, element)) |
|
|
calls.push(API.saveConfig(element)) |
|
|
// turn the save button grey when clicked |
|
|
// Turn the save button grey when clicked |
|
|
oidcSaveButtonDisabled = true |
|
|
oidcSaveButtonDisabled = true |
|
|
originalOidcDoc = cloneDeep(providers.oidc) |
|
|
originalOidcDoc = cloneDeep(providers.oidc) |
|
|
} |
|
|
} |
|
|
@ -189,71 +189,70 @@ |
|
|
`Please fill in all required ${ConfigTypes.Google} fields` |
|
|
`Please fill in all required ${ConfigTypes.Google} fields` |
|
|
) |
|
|
) |
|
|
} else { |
|
|
} else { |
|
|
calls.push(api.post(`/api/global/configs`, element)) |
|
|
calls.push(API.saveConfig(element)) |
|
|
googleSaveButtonDisabled = true |
|
|
googleSaveButtonDisabled = true |
|
|
originalGoogleDoc = cloneDeep(providers.google) |
|
|
originalGoogleDoc = cloneDeep(providers.google) |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
}) |
|
|
}) |
|
|
calls.length && |
|
|
|
|
|
|
|
|
if (calls.length) { |
|
|
Promise.all(calls) |
|
|
Promise.all(calls) |
|
|
.then(responses => { |
|
|
|
|
|
return Promise.all( |
|
|
|
|
|
responses.map(response => { |
|
|
|
|
|
return response.json() |
|
|
|
|
|
}) |
|
|
|
|
|
) |
|
|
|
|
|
}) |
|
|
|
|
|
.then(data => { |
|
|
.then(data => { |
|
|
data.forEach(res => { |
|
|
data.forEach(res => { |
|
|
providers[res.type]._rev = res._rev |
|
|
providers[res.type]._rev = res._rev |
|
|
providers[res.type]._id = res._id |
|
|
providers[res.type]._id = res._id |
|
|
}) |
|
|
}) |
|
|
notifications.success(`Settings saved.`) |
|
|
notifications.success(`Settings saved`) |
|
|
analytics.captureEvent(Events.SSO.SAVED) |
|
|
analytics.captureEvent(Events.SSO.SAVED) |
|
|
}) |
|
|
}) |
|
|
.catch(err => { |
|
|
.catch(error => { |
|
|
notifications.error(`Failed to update auth settings. ${err}`) |
|
|
notifications.error(`Failed to update auth settings`) |
|
|
throw new Error(err.message) |
|
|
console.error(error.message) |
|
|
}) |
|
|
}) |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
onMount(async () => { |
|
|
onMount(async () => { |
|
|
await organisation.init() |
|
|
await organisation.init() |
|
|
// fetch the configs for oauth |
|
|
|
|
|
const googleResponse = await api.get( |
|
|
|
|
|
`/api/global/configs/${ConfigTypes.Google}` |
|
|
|
|
|
) |
|
|
|
|
|
const googleDoc = await googleResponse.json() |
|
|
|
|
|
|
|
|
|
|
|
if (!googleDoc._id) { |
|
|
// Fetch Google config |
|
|
|
|
|
let googleDoc |
|
|
|
|
|
try { |
|
|
|
|
|
googleDoc = await API.getConfig(ConfigTypes.Google) |
|
|
|
|
|
} catch (error) { |
|
|
|
|
|
notifications.error("Error fetching Google OAuth config") |
|
|
|
|
|
} |
|
|
|
|
|
if (!googleDoc?._id) { |
|
|
providers.google = { |
|
|
providers.google = { |
|
|
type: ConfigTypes.Google, |
|
|
type: ConfigTypes.Google, |
|
|
config: { activated: true }, |
|
|
config: { activated: true }, |
|
|
} |
|
|
} |
|
|
originalGoogleDoc = cloneDeep(googleDoc) |
|
|
originalGoogleDoc = cloneDeep(googleDoc) |
|
|
} else { |
|
|
} else { |
|
|
// default activated to true for older configs |
|
|
// Default activated to true for older configs |
|
|
if (googleDoc.config.activated === undefined) { |
|
|
if (googleDoc.config.activated === undefined) { |
|
|
googleDoc.config.activated = true |
|
|
googleDoc.config.activated = true |
|
|
} |
|
|
} |
|
|
originalGoogleDoc = cloneDeep(googleDoc) |
|
|
originalGoogleDoc = cloneDeep(googleDoc) |
|
|
providers.google = googleDoc |
|
|
providers.google = googleDoc |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
googleCallbackUrl = providers?.google?.config?.callbackURL |
|
|
googleCallbackUrl = providers?.google?.config?.callbackURL |
|
|
|
|
|
|
|
|
//Get the list of user uploaded logos and push it to the dropdown options. |
|
|
// Get the list of user uploaded logos and push it to the dropdown options. |
|
|
//This needs to be done before the config call so they're available when the dropdown renders |
|
|
// This needs to be done before the config call so they're available when |
|
|
const res = await api.get(`/api/global/configs/logos_oidc`) |
|
|
// the dropdown renders. |
|
|
const configSettings = await res.json() |
|
|
let oidcLogos |
|
|
|
|
|
try { |
|
|
if (configSettings.config) { |
|
|
oidcLogos = await API.getOIDCLogos() |
|
|
const logoKeys = Object.keys(configSettings.config) |
|
|
} catch (error) { |
|
|
|
|
|
notifications.error("Error fetching OIDC logos") |
|
|
|
|
|
} |
|
|
|
|
|
if (oidcLogos?.config) { |
|
|
|
|
|
const logoKeys = Object.keys(oidcLogos.config) |
|
|
logoKeys.map(logoKey => { |
|
|
logoKeys.map(logoKey => { |
|
|
const logoUrl = configSettings.config[logoKey] |
|
|
const logoUrl = oidcLogos.config[logoKey] |
|
|
iconDropdownOptions.unshift({ |
|
|
iconDropdownOptions.unshift({ |
|
|
label: logoKey, |
|
|
label: logoKey, |
|
|
value: logoKey, |
|
|
value: logoKey, |
|
|
@ -261,11 +260,15 @@ |
|
|
}) |
|
|
}) |
|
|
}) |
|
|
}) |
|
|
} |
|
|
} |
|
|
const oidcResponse = await api.get( |
|
|
|
|
|
`/api/global/configs/${ConfigTypes.OIDC}` |
|
|
// Fetch OIDC config |
|
|
) |
|
|
let oidcDoc |
|
|
const oidcDoc = await oidcResponse.json() |
|
|
try { |
|
|
if (!oidcDoc._id) { |
|
|
oidcDoc = await API.getConfig(ConfigTypes.OIDC) |
|
|
|
|
|
} catch (error) { |
|
|
|
|
|
notifications.error("Error fetching OIDC config") |
|
|
|
|
|
} |
|
|
|
|
|
if (!oidcDoc?._id) { |
|
|
providers.oidc = { |
|
|
providers.oidc = { |
|
|
type: ConfigTypes.OIDC, |
|
|
type: ConfigTypes.OIDC, |
|
|
config: { configs: [{ activated: true }] }, |
|
|
config: { configs: [{ activated: true }] }, |
|
|
|