Add UUID to each oidc config to distinguish each provider

This commit is contained in:
Peter Clement 2021-07-13 15:52:21 +01:00
parent af792cc09e
commit 9dd05ec96e
5 changed files with 29 additions and 11 deletions

View File

@ -7,14 +7,21 @@ const mockEmail = "mock@budibase.com"
const mockAccessToken = "mockAccessToken" const mockAccessToken = "mockAccessToken"
const mockRefreshToken = "mockRefreshToken" const mockRefreshToken = "mockRefreshToken"
const buildOauth2 = (accessToken=mockAccessToken, refreshToken=mockRefreshToken) => ( const buildOauth2 = (
{ accessToken = mockAccessToken,
refreshToken = mockRefreshToken
) => ({
accessToken: accessToken, accessToken: accessToken,
refreshToken: refreshToken, refreshToken: refreshToken,
} })
)
const buildThirdPartyUser = (provider, providerType, profile, email=mockEmail, oauth2=buildOauth2()) => ({ const buildThirdPartyUser = (
provider,
providerType,
profile,
email = mockEmail,
oauth2 = buildOauth2()
) => ({
provider: provider, provider: provider,
providerType: providerType, providerType: providerType,
userId: profile.id, userId: profile.id,
@ -29,5 +36,5 @@ exports.data = {
email: mockEmail, email: mockEmail,
accessToken: mockAccessToken, accessToken: mockAccessToken,
refreshToken: mockRefreshToken, refreshToken: mockRefreshToken,
buildThirdPartyUser buildThirdPartyUser,
} }

View File

@ -19,6 +19,7 @@
import { onMount } from "svelte" import { onMount } from "svelte"
import api from "builderStore/api" import api from "builderStore/api"
import { organisation } from "stores/portal" import { organisation } from "stores/portal"
import { uuid } from "builderStore/uuid"
const ConfigTypes = { const ConfigTypes = {
Google: "google", Google: "google",
@ -87,10 +88,17 @@
const providers = { google, oidc } const providers = { google, oidc }
async function save(docs) { async function save(docs) {
console.log(docs)
// only if the user has provided an image, upload it. // only if the user has provided an image, upload it.
image && uploadLogo(image) image && uploadLogo(image)
let calls = [] let calls = []
docs.forEach(element => { docs.forEach(element => {
//Add a UUID here so each config is distinguishable when it arrives at the login page.
if (element.type === "oidc") {
element.config.configs.forEach(config => {
config.uuid = uuid()
})
}
calls.push(api.post(`/api/admin/configs`, element)) calls.push(api.post(`/api/admin/configs`, element))
}) })
Promise.all(calls) Promise.all(calls)
@ -184,7 +192,7 @@
To allow users to authenticate using their Google accounts, fill out the To allow users to authenticate using their Google accounts, fill out the
fields below. fields below.
</Body> </Body>
</Layout>dddd </Layout>
<Layout gap="XS" noPadding> <Layout gap="XS" noPadding>
{#each GoogleConfigFields.Google as field} {#each GoogleConfigFields.Google as field}
<div class="form-row"> <div class="form-row">

View File

@ -4,6 +4,7 @@ import api from "builderStore/api"
const OIDC_CONFIG = { const OIDC_CONFIG = {
logo: undefined, logo: undefined,
name: undefined, name: undefined,
uuid: undefined,
} }
export function createOidcStore() { export function createOidcStore() {

View File

@ -113,6 +113,7 @@ exports.publicOidc = async function (ctx) {
return { return {
logo: config.logo, logo: config.logo,
name: config.name, name: config.name,
uuid: config.uuid,
} }
}) })
ctx.body = partialOidcCofig ctx.body = partialOidcCofig

View File

@ -51,6 +51,7 @@ function oidcValidation() {
configUrl: Joi.string().required(), configUrl: Joi.string().required(),
logo: Joi.string().optional(), logo: Joi.string().optional(),
name: Joi.string().optional(), name: Joi.string().optional(),
uuid: Joi.string().required(),
}) })
).required(true) ).required(true)
}).unknown(true) }).unknown(true)