|
|
|
@ -1,5 +1,6 @@ |
|
|
|
<script> |
|
|
|
import GoogleLogo from "./_logos/Google.svelte" |
|
|
|
import OIDCLogo from "./_logos/OIDC.svelte" |
|
|
|
import { |
|
|
|
Button, |
|
|
|
Heading, |
|
|
|
@ -9,20 +10,22 @@ |
|
|
|
Layout, |
|
|
|
Input, |
|
|
|
Body, |
|
|
|
Select |
|
|
|
} from "@budibase/bbui" |
|
|
|
import { onMount } from "svelte" |
|
|
|
import api from "builderStore/api" |
|
|
|
|
|
|
|
const ConfigTypes = { |
|
|
|
Google: "google", |
|
|
|
OIDC: "oidc", |
|
|
|
// Github: "github", |
|
|
|
// AzureAD: "ad", |
|
|
|
} |
|
|
|
|
|
|
|
const ConfigFields = { |
|
|
|
const GoogleConfigFields = { |
|
|
|
Google: ["clientID", "clientSecret", "callbackURL"], |
|
|
|
} |
|
|
|
const ConfigLabels = { |
|
|
|
const GoogleConfigLabels = { |
|
|
|
Google: { |
|
|
|
clientID: "Client ID", |
|
|
|
clientSecret: "Client secret", |
|
|
|
@ -30,21 +33,58 @@ |
|
|
|
}, |
|
|
|
} |
|
|
|
|
|
|
|
const OIDCConfigFields = { |
|
|
|
Oidc: [ |
|
|
|
"issuer", |
|
|
|
"authUrl", |
|
|
|
"tokenUrl", |
|
|
|
"userInfoUrl", |
|
|
|
"clientId", |
|
|
|
"clientSecret", |
|
|
|
"callbackUrl", |
|
|
|
"name" |
|
|
|
], |
|
|
|
} |
|
|
|
const OIDCConfigLabels = { |
|
|
|
Oidc: { |
|
|
|
issuer: "Issuer", |
|
|
|
authUrl: "Authorization URL", |
|
|
|
tokenUrl: "Token URL", |
|
|
|
userInfoUrl: "User Info URL", |
|
|
|
clientId: "Client ID", |
|
|
|
clientSecret: "Client Secret", |
|
|
|
callbackUrl: "Callback URL", |
|
|
|
name: "Name" |
|
|
|
}, |
|
|
|
} |
|
|
|
|
|
|
|
let google |
|
|
|
let oidc |
|
|
|
const providers = {google, oidc} |
|
|
|
|
|
|
|
async function save(doc) { |
|
|
|
try { |
|
|
|
// Save an oauth config |
|
|
|
const response = await api.post(`/api/admin/configs`, doc) |
|
|
|
const json = await response.json() |
|
|
|
if (response.status !== 200) throw new Error(json.message) |
|
|
|
google._rev = json._rev |
|
|
|
google._id = json._id |
|
|
|
|
|
|
|
notifications.success(`Settings saved.`) |
|
|
|
} catch (err) { |
|
|
|
notifications.error(`Failed to update OAuth settings. ${err}`) |
|
|
|
} |
|
|
|
async function save(docs) { |
|
|
|
let calls = [] |
|
|
|
docs.forEach(element => { |
|
|
|
calls.push(api.post(`/api/admin/configs`, element)) |
|
|
|
}) |
|
|
|
Promise.all(calls) |
|
|
|
.then(responses => { |
|
|
|
return Promise.all(responses.map(response => { |
|
|
|
return response.json() |
|
|
|
})) |
|
|
|
}).then(data => { |
|
|
|
data.forEach(res => { |
|
|
|
providers[res.type]._rev = res._rev |
|
|
|
providers[res.type]._id = res._id |
|
|
|
}) |
|
|
|
//res.json()._rev = res.json()._rev |
|
|
|
//res.json().id = res.json().id |
|
|
|
notifications.success(`Settings saved.`) |
|
|
|
}) |
|
|
|
.catch(err => { |
|
|
|
notifications.error(`Failed to update OAuth settings. ${err}`) |
|
|
|
throw new Error(err.message) |
|
|
|
}) |
|
|
|
} |
|
|
|
|
|
|
|
onMount(async () => { |
|
|
|
@ -55,14 +95,28 @@ |
|
|
|
const googleDoc = await googleResponse.json() |
|
|
|
|
|
|
|
if (!googleDoc._id) { |
|
|
|
google = { |
|
|
|
providers.google = { |
|
|
|
type: ConfigTypes.Google, |
|
|
|
config: {}, |
|
|
|
} |
|
|
|
} else { |
|
|
|
google = googleDoc |
|
|
|
providers.google = googleDoc |
|
|
|
} |
|
|
|
|
|
|
|
const oidcResponse = await api.get(`/api/admin/configs/${ConfigTypes.OIDC}`) |
|
|
|
const oidcDoc = await oidcResponse.json() |
|
|
|
|
|
|
|
if (!oidcDoc._id) { |
|
|
|
providers.oidc = { |
|
|
|
type: ConfigTypes.OIDC, |
|
|
|
config: {}, |
|
|
|
} |
|
|
|
} else { |
|
|
|
providers.oidc = oidcDoc |
|
|
|
} |
|
|
|
}) |
|
|
|
}) |
|
|
|
let fileInput |
|
|
|
|
|
|
|
</script> |
|
|
|
|
|
|
|
<Layout> |
|
|
|
@ -74,7 +128,7 @@ |
|
|
|
below. |
|
|
|
</Body> |
|
|
|
</Layout> |
|
|
|
{#if google} |
|
|
|
{#if providers.google} |
|
|
|
<Divider /> |
|
|
|
<Layout gap="XS" noPadding> |
|
|
|
<Heading size="S"> |
|
|
|
@ -89,17 +143,50 @@ |
|
|
|
</Body> |
|
|
|
</Layout> |
|
|
|
<Layout gap="XS" noPadding> |
|
|
|
{#each ConfigFields.Google as field} |
|
|
|
{#each GoogleConfigFields.Google as field} |
|
|
|
<div class="form-row"> |
|
|
|
<Label size="L">{GoogleConfigLabels.Google[field]}</Label> |
|
|
|
<Input bind:value={providers.google.config[field]} /> |
|
|
|
</div> |
|
|
|
{/each} |
|
|
|
</Layout> |
|
|
|
{/if} |
|
|
|
{#if providers.oidc} |
|
|
|
<Divider /> |
|
|
|
<Layout gap="XS" noPadding> |
|
|
|
<Heading size="S"> |
|
|
|
<span> |
|
|
|
<GoogleLogo /> |
|
|
|
OpenID Connect |
|
|
|
</span> |
|
|
|
</Heading> |
|
|
|
<Body size="S"> |
|
|
|
To allow users to authenticate using OIDC, fill out the fields below. |
|
|
|
</Body> |
|
|
|
</Layout> |
|
|
|
<Layout gap="XS" noPadding> |
|
|
|
{#each OIDCConfigFields.Oidc as field} |
|
|
|
<div class="form-row"> |
|
|
|
<Label size="L">{ConfigLabels.Google[field]}</Label> |
|
|
|
<Input bind:value={google.config[field]} /> |
|
|
|
<Label size="L">{OIDCConfigLabels.Oidc[field]}</Label> |
|
|
|
<Input bind:value={providers.oidc.config[field]} /> |
|
|
|
</div> |
|
|
|
{/each} |
|
|
|
<Body size="S"> |
|
|
|
To customize your login button, fill out the fields below. |
|
|
|
</Body> |
|
|
|
<div class="form-row"> |
|
|
|
<Label size="L">{OIDCConfigLabels.Oidc['name']}</Label> |
|
|
|
<Select |
|
|
|
options={["Upload File"]} |
|
|
|
placeholder={null} |
|
|
|
/> |
|
|
|
|
|
|
|
</div> |
|
|
|
</Layout> |
|
|
|
<div> |
|
|
|
<Button cta on:click={() => save(google)}>Save</Button> |
|
|
|
</div> |
|
|
|
{/if} |
|
|
|
<div> |
|
|
|
<Button cta on:click={() => save([providers.google, providers.oidc])}>Save</Button> |
|
|
|
</div> |
|
|
|
</Layout> |
|
|
|
|
|
|
|
<style> |
|
|
|
@ -109,7 +196,6 @@ |
|
|
|
grid-gap: var(--spacing-l); |
|
|
|
align-items: center; |
|
|
|
} |
|
|
|
|
|
|
|
span { |
|
|
|
display: flex; |
|
|
|
align-items: center; |
|
|
|
|