From 18a431df12748e1fb2ac091788d4ac64272aa5fc Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Wed, 19 Mar 2025 16:25:30 +0100 Subject: [PATCH] Store from frontend --- .../oauth2/OAuth2ConfigModalContent.svelte | 35 ++++++++++++++++++- packages/builder/src/stores/builder/oauth2.ts | 1 + packages/server/src/api/routes/oauth2.ts | 5 ++- 3 files changed, 39 insertions(+), 2 deletions(-) diff --git a/packages/builder/src/pages/builder/app/[application]/settings/oauth2/OAuth2ConfigModalContent.svelte b/packages/builder/src/pages/builder/app/[application]/settings/oauth2/OAuth2ConfigModalContent.svelte index 93ef863a7d..83b4072282 100644 --- a/packages/builder/src/pages/builder/app/[application]/settings/oauth2/OAuth2ConfigModalContent.svelte +++ b/packages/builder/src/pages/builder/app/[application]/settings/oauth2/OAuth2ConfigModalContent.svelte @@ -10,8 +10,12 @@ Link, ModalContent, notifications, + Select, } from "@budibase/bbui" - import { PASSWORD_REPLACEMENT } from "@budibase/types" + import { + OAuth2CredentialsMethod, + PASSWORD_REPLACEMENT, + } from "@budibase/types" import type { ZodType } from "zod" import { z } from "zod" @@ -27,6 +31,17 @@ ? "Create new OAuth2 connection" : "Edit OAuth2 connection" + const methods = [ + { + label: "Basic", + value: OAuth2CredentialsMethod.HEADER, + }, + { + label: "Post", + value: OAuth2CredentialsMethod.BODY, + }, + ] + const requiredString = (errorMessage: string) => z.string({ required_error: errorMessage }).trim().min(1, errorMessage) @@ -45,6 +60,9 @@ url: requiredString("Url is required.").url(), clientId: requiredString("Client ID is required."), clientSecret: requiredString("Client secret is required."), + method: z.nativeEnum(OAuth2CredentialsMethod, { + message: "Authentication method is required.", + }), }) satisfies ZodType const validationResult = validator.safeParse(config) @@ -119,6 +137,21 @@ bind:value={data.name} error={errors.name} /> + { url: c.url, clientId: c.clientId, clientSecret: c.clientSecret, + method: c.method, })), loading: false, })) diff --git a/packages/server/src/api/routes/oauth2.ts b/packages/server/src/api/routes/oauth2.ts index a0e68eff84..857a4dae92 100644 --- a/packages/server/src/api/routes/oauth2.ts +++ b/packages/server/src/api/routes/oauth2.ts @@ -1,5 +1,5 @@ import Router from "@koa/router" -import { PermissionType } from "@budibase/types" +import { OAuth2CredentialsMethod, PermissionType } from "@budibase/types" import { middleware } from "@budibase/backend-core" import authorized from "../../middleware/authorized" @@ -13,6 +13,9 @@ function oAuth2ConfigValidator() { url: Joi.string().required(), clientId: Joi.string().required(), clientSecret: Joi.string().required(), + method: Joi.string() + .required() + .valid(...Object.values(OAuth2CredentialsMethod)), }), { allowUnknown: false } )