diff --git a/lerna.json b/lerna.json
index ed4f2c82a4..66fd740bc5 100644
--- a/lerna.json
+++ b/lerna.json
@@ -1,5 +1,5 @@
{
- "version": "1.0.19-alpha.1",
+ "version": "1.0.19-alpha.3",
"npmClient": "yarn",
"packages": [
"packages/*"
diff --git a/packages/auth/package.json b/packages/auth/package.json
index 98c1d538eb..9f096630c9 100644
--- a/packages/auth/package.json
+++ b/packages/auth/package.json
@@ -1,6 +1,6 @@
{
"name": "@budibase/auth",
- "version": "1.0.19-alpha.1",
+ "version": "1.0.19-alpha.3",
"description": "Authentication middlewares for budibase builder and apps",
"main": "src/index.js",
"author": "Budibase",
diff --git a/packages/bbui/package.json b/packages/bbui/package.json
index 9e682b77bc..b9f779409b 100644
--- a/packages/bbui/package.json
+++ b/packages/bbui/package.json
@@ -1,7 +1,7 @@
{
"name": "@budibase/bbui",
"description": "A UI solution used in the different Budibase projects.",
- "version": "1.0.19-alpha.1",
+ "version": "1.0.19-alpha.3",
"license": "MPL-2.0",
"svelte": "src/index.js",
"module": "dist/bbui.es.js",
diff --git a/packages/bbui/src/Modal/ModalContent.svelte b/packages/bbui/src/Modal/ModalContent.svelte
index 7f2d7fbdb9..c18be1e4e1 100644
--- a/packages/bbui/src/Modal/ModalContent.svelte
+++ b/packages/bbui/src/Modal/ModalContent.svelte
@@ -21,6 +21,7 @@
export let showSecondaryButton = false
export let secondaryButtonText = undefined
export let secondaryAction = undefined
+ export let secondaryButtonWarning = false
const { hide, cancel } = getContext(Context.Modal)
let loading = false
@@ -88,8 +89,11 @@
{#if showSecondaryButton && secondaryButtonText && secondaryAction}
- {secondaryButtonText}
{/if}
diff --git a/packages/builder/package.json b/packages/builder/package.json
index f91514423a..1a19246ba0 100644
--- a/packages/builder/package.json
+++ b/packages/builder/package.json
@@ -1,6 +1,6 @@
{
"name": "@budibase/builder",
- "version": "1.0.19-alpha.1",
+ "version": "1.0.19-alpha.3",
"license": "GPL-3.0",
"private": true,
"scripts": {
@@ -65,10 +65,10 @@
}
},
"dependencies": {
- "@budibase/bbui": "^1.0.19-alpha.1",
- "@budibase/client": "^1.0.19-alpha.1",
+ "@budibase/bbui": "^1.0.19-alpha.3",
+ "@budibase/client": "^1.0.19-alpha.3",
"@budibase/colorpicker": "1.1.2",
- "@budibase/string-templates": "^1.0.19-alpha.1",
+ "@budibase/string-templates": "^1.0.19-alpha.3",
"@sentry/browser": "5.19.1",
"@spectrum-css/page": "^3.0.1",
"@spectrum-css/vars": "^3.0.1",
diff --git a/packages/builder/src/components/backend/DatasourceNavigator/TableIntegrationMenu/PlusConfigForm.svelte b/packages/builder/src/components/backend/DatasourceNavigator/TableIntegrationMenu/PlusConfigForm.svelte
index 01ba071a3f..f736d29bee 100644
--- a/packages/builder/src/components/backend/DatasourceNavigator/TableIntegrationMenu/PlusConfigForm.svelte
+++ b/packages/builder/src/components/backend/DatasourceNavigator/TableIntegrationMenu/PlusConfigForm.svelte
@@ -12,7 +12,7 @@
import { datasources, integrations, tables } from "stores/backend"
import CreateEditRelationship from "components/backend/Datasources/CreateEditRelationship.svelte"
import CreateExternalTableModal from "./CreateExternalTableModal.svelte"
- import ArrayRenderer from "components/common/ArrayRenderer.svelte"
+ import ArrayRenderer from "components/common/renderers/ArrayRenderer.svelte"
import ConfirmDialog from "components/common/ConfirmDialog.svelte"
import { goto } from "@roxi/routify"
diff --git a/packages/builder/src/components/backend/DatasourceNavigator/TableIntegrationMenu/RestExtraConfigForm.svelte b/packages/builder/src/components/backend/DatasourceNavigator/TableIntegrationMenu/rest/RestExtraConfigForm.svelte
similarity index 65%
rename from packages/builder/src/components/backend/DatasourceNavigator/TableIntegrationMenu/RestExtraConfigForm.svelte
rename to packages/builder/src/components/backend/DatasourceNavigator/TableIntegrationMenu/rest/RestExtraConfigForm.svelte
index ce3881d82c..0272463d92 100644
--- a/packages/builder/src/components/backend/DatasourceNavigator/TableIntegrationMenu/RestExtraConfigForm.svelte
+++ b/packages/builder/src/components/backend/DatasourceNavigator/TableIntegrationMenu/rest/RestExtraConfigForm.svelte
@@ -1,6 +1,7 @@
-
@@ -405,4 +450,12 @@
margin-top: var(--spacing-xl);
justify-content: center;
}
+ .auth-container {
+ width: 100%;
+ display: flex;
+ justify-content: space-between;
+ }
+ .auth-select {
+ width: 200px;
+ }
diff --git a/packages/cli/package.json b/packages/cli/package.json
index fb47f73298..931123b962 100644
--- a/packages/cli/package.json
+++ b/packages/cli/package.json
@@ -1,6 +1,6 @@
{
"name": "@budibase/cli",
- "version": "1.0.19-alpha.1",
+ "version": "1.0.19-alpha.3",
"description": "Budibase CLI, for developers, self hosting and migrations.",
"main": "src/index.js",
"bin": {
diff --git a/packages/client/package.json b/packages/client/package.json
index c0717200f9..8a5fdfdff0 100644
--- a/packages/client/package.json
+++ b/packages/client/package.json
@@ -1,6 +1,6 @@
{
"name": "@budibase/client",
- "version": "1.0.19-alpha.1",
+ "version": "1.0.19-alpha.3",
"license": "MPL-2.0",
"module": "dist/budibase-client.js",
"main": "dist/budibase-client.js",
@@ -19,9 +19,9 @@
"dev:builder": "rollup -cw"
},
"dependencies": {
- "@budibase/bbui": "^1.0.19-alpha.1",
+ "@budibase/bbui": "^1.0.19-alpha.3",
"@budibase/standard-components": "^0.9.139",
- "@budibase/string-templates": "^1.0.19-alpha.1",
+ "@budibase/string-templates": "^1.0.19-alpha.3",
"regexparam": "^1.3.0",
"shortid": "^2.2.15",
"svelte-spa-router": "^3.0.5"
diff --git a/packages/server/package.json b/packages/server/package.json
index 1f30a67695..7205c1173e 100644
--- a/packages/server/package.json
+++ b/packages/server/package.json
@@ -1,7 +1,7 @@
{
"name": "@budibase/server",
"email": "hi@budibase.com",
- "version": "1.0.19-alpha.1",
+ "version": "1.0.19-alpha.3",
"description": "Budibase Web Server",
"main": "src/index.ts",
"repository": {
@@ -70,9 +70,9 @@
"license": "GPL-3.0",
"dependencies": {
"@apidevtools/swagger-parser": "^10.0.3",
- "@budibase/auth": "^1.0.19-alpha.1",
- "@budibase/client": "^1.0.19-alpha.1",
- "@budibase/string-templates": "^1.0.19-alpha.1",
+ "@budibase/auth": "^1.0.19-alpha.3",
+ "@budibase/client": "^1.0.19-alpha.3",
+ "@budibase/string-templates": "^1.0.19-alpha.3",
"@bull-board/api": "^3.7.0",
"@bull-board/koa": "^3.7.0",
"@elastic/elasticsearch": "7.10.0",
diff --git a/packages/server/src/definitions/datasource.ts b/packages/server/src/definitions/datasource.ts
index 0ca8fdcae9..148d8f2875 100644
--- a/packages/server/src/definitions/datasource.ts
+++ b/packages/server/src/definitions/datasource.ts
@@ -196,6 +196,27 @@ export interface Datasource extends Base {
}
}
+export enum AuthType {
+ BASIC = "basic",
+ BEARER = "bearer",
+}
+
+interface AuthConfig {
+ _id: string
+ name: string
+ type: AuthType
+ config: BasicAuthConfig | BearerAuthConfig
+}
+
+export interface BasicAuthConfig {
+ username: string
+ password: string
+}
+
+export interface BearerAuthConfig {
+ token: string
+}
+
export interface QueryParameter {
name: string
default: string
@@ -210,6 +231,7 @@ export interface RestQueryFields {
bodyType: string
json: object
method: string
+ authConfigId: string
}
export interface RestConfig {
@@ -217,6 +239,7 @@ export interface RestConfig {
defaultHeaders: {
[key: string]: any
}
+ authConfigs: AuthConfig[]
}
export interface Query {
diff --git a/packages/server/src/integrations/rest.ts b/packages/server/src/integrations/rest.ts
index 4fa43b9f84..f87e5b7416 100644
--- a/packages/server/src/integrations/rest.ts
+++ b/packages/server/src/integrations/rest.ts
@@ -4,6 +4,9 @@ import {
QueryTypes,
RestConfig,
RestQueryFields as RestQuery,
+ AuthType,
+ BasicAuthConfig,
+ BearerAuthConfig,
} from "../definitions/datasource"
import { IntegrationBase } from "./base/IntegrationBase"
@@ -116,9 +119,17 @@ module RestModule {
if (contentType.includes("application/json")) {
data = await response.json()
raw = JSON.stringify(data)
- } else if (contentType.includes("text/xml") || contentType.includes("application/xml")) {
+ } else if (
+ contentType.includes("text/xml") ||
+ contentType.includes("application/xml")
+ ) {
const rawXml = await response.text()
- data = await xmlParser(rawXml, { explicitArray: false, trim: true, explicitRoot: false }) || {}
+ data =
+ (await xmlParser(rawXml, {
+ explicitArray: false,
+ trim: true,
+ explicitRoot: false,
+ })) || {}
// there is only one structure, its an array, return the array so it appears as rows
const keys = Object.keys(data)
if (keys.length === 1 && Array.isArray(data[keys[0]])) {
@@ -210,6 +221,35 @@ module RestModule {
return input
}
+ getAuthHeaders(authConfigId: string): { [key: string]: any } {
+ let headers: any = {}
+
+ if (this.config.authConfigs && authConfigId) {
+ const authConfig = this.config.authConfigs.filter(
+ c => c._id === authConfigId
+ )[0]
+ // check the config still exists before proceeding
+ // if not - do nothing
+ if (authConfig) {
+ let config
+ switch (authConfig.type) {
+ case AuthType.BASIC:
+ config = authConfig.config as BasicAuthConfig
+ headers.Authorization = `Basic ${Buffer.from(
+ `${config.username}:${config.password}`
+ ).toString("base64")}`
+ break
+ case AuthType.BEARER:
+ config = authConfig.config as BearerAuthConfig
+ headers.Authorization = `Bearer ${config.token}`
+ break
+ }
+ }
+ }
+
+ return headers
+ }
+
async _req(query: RestQuery) {
const {
path = "",
@@ -219,10 +259,14 @@ module RestModule {
disabledHeaders,
bodyType,
requestBody,
+ authConfigId,
} = query
+ const authHeaders = this.getAuthHeaders(authConfigId)
+
this.headers = {
...this.config.defaultHeaders,
...headers,
+ ...authHeaders,
}
if (disabledHeaders) {
@@ -239,7 +283,8 @@ module RestModule {
}
this.startTimeMs = performance.now()
- const response = await fetch(this.getUrl(path, queryString), input)
+ const url = this.getUrl(path, queryString)
+ const response = await fetch(url, input)
return await this.parseResponse(response)
}
@@ -267,5 +312,6 @@ module RestModule {
module.exports = {
schema: SCHEMA,
integration: RestIntegration,
+ AuthType,
}
}
diff --git a/packages/server/src/integrations/tests/rest.spec.js b/packages/server/src/integrations/tests/rest.spec.js
index 58033e68a4..6c1d989124 100644
--- a/packages/server/src/integrations/tests/rest.spec.js
+++ b/packages/server/src/integrations/tests/rest.spec.js
@@ -12,6 +12,7 @@ jest.mock("node-fetch", () =>
)
const fetch = require("node-fetch")
const RestIntegration = require("../rest")
+const { AuthType } = require("../rest")
class TestConfiguration {
constructor(config = {}) {
@@ -112,4 +113,58 @@ describe("REST Integration", () => {
body: '{"name":"test"}',
})
})
+
+ describe("authentication", () => {
+ const basicAuth = {
+ _id: "c59c14bd1898a43baa08da68959b24686",
+ name: "basic-1",
+ type : AuthType.BASIC,
+ config : {
+ username: "user",
+ password: "password"
+ }
+ }
+
+ const bearerAuth = {
+ _id: "0d91d732f34e4befabeff50b392a8ff3",
+ name: "bearer-1",
+ type : AuthType.BEARER,
+ config : {
+ "token": "mytoken"
+ }
+ }
+
+ beforeEach(() => {
+ config = new TestConfiguration({
+ url: BASE_URL,
+ authConfigs : [basicAuth, bearerAuth]
+ })
+ })
+
+ it("adds basic auth", async () => {
+ const query = {
+ authConfigId: "c59c14bd1898a43baa08da68959b24686"
+ }
+ await config.integration.read(query)
+ expect(fetch).toHaveBeenCalledWith(`${BASE_URL}/?`, {
+ method: "GET",
+ headers: {
+ Authorization: "Basic dXNlcjpwYXNzd29yZA=="
+ },
+ })
+ })
+
+ it("adds bearer auth", async () => {
+ const query = {
+ authConfigId: "0d91d732f34e4befabeff50b392a8ff3"
+ }
+ await config.integration.read(query)
+ expect(fetch).toHaveBeenCalledWith(`${BASE_URL}/?`, {
+ method: "GET",
+ headers: {
+ Authorization: "Bearer mytoken"
+ },
+ })
+ })
+ })
})
diff --git a/packages/string-templates/package.json b/packages/string-templates/package.json
index e2d14d8bf7..1cc72023df 100644
--- a/packages/string-templates/package.json
+++ b/packages/string-templates/package.json
@@ -1,6 +1,6 @@
{
"name": "@budibase/string-templates",
- "version": "1.0.19-alpha.1",
+ "version": "1.0.19-alpha.3",
"description": "Handlebars wrapper for Budibase templating.",
"main": "src/index.cjs",
"module": "dist/bundle.mjs",
diff --git a/packages/worker/package.json b/packages/worker/package.json
index 58372fd187..3d2c314091 100644
--- a/packages/worker/package.json
+++ b/packages/worker/package.json
@@ -1,7 +1,7 @@
{
"name": "@budibase/worker",
"email": "hi@budibase.com",
- "version": "1.0.19-alpha.1",
+ "version": "1.0.19-alpha.3",
"description": "Budibase background service",
"main": "src/index.js",
"repository": {
@@ -29,8 +29,8 @@
"author": "Budibase",
"license": "GPL-3.0",
"dependencies": {
- "@budibase/auth": "^1.0.19-alpha.1",
- "@budibase/string-templates": "^1.0.19-alpha.1",
+ "@budibase/auth": "^1.0.19-alpha.3",
+ "@budibase/string-templates": "^1.0.19-alpha.3",
"@koa/router": "^8.0.0",
"@sentry/node": "^6.0.0",
"@techpass/passport-openidconnect": "^0.3.0",