Store from frontend

This commit is contained in:
Adria Navarro 2025-03-19 16:25:30 +01:00
parent 8f14194ee4
commit 18a431df12
3 changed files with 39 additions and 2 deletions

View File

@ -10,8 +10,12 @@
Link, Link,
ModalContent, ModalContent,
notifications, notifications,
Select,
} from "@budibase/bbui" } from "@budibase/bbui"
import { PASSWORD_REPLACEMENT } from "@budibase/types" import {
OAuth2CredentialsMethod,
PASSWORD_REPLACEMENT,
} from "@budibase/types"
import type { ZodType } from "zod" import type { ZodType } from "zod"
import { z } from "zod" import { z } from "zod"
@ -27,6 +31,17 @@
? "Create new OAuth2 connection" ? "Create new OAuth2 connection"
: "Edit OAuth2 connection" : "Edit OAuth2 connection"
const methods = [
{
label: "Basic",
value: OAuth2CredentialsMethod.HEADER,
},
{
label: "Post",
value: OAuth2CredentialsMethod.BODY,
},
]
const requiredString = (errorMessage: string) => const requiredString = (errorMessage: string) =>
z.string({ required_error: errorMessage }).trim().min(1, errorMessage) z.string({ required_error: errorMessage }).trim().min(1, errorMessage)
@ -45,6 +60,9 @@
url: requiredString("Url is required.").url(), url: requiredString("Url is required.").url(),
clientId: requiredString("Client ID is required."), clientId: requiredString("Client ID is required."),
clientSecret: requiredString("Client secret is required."), clientSecret: requiredString("Client secret is required."),
method: z.nativeEnum(OAuth2CredentialsMethod, {
message: "Authentication method is required.",
}),
}) satisfies ZodType<UpsertOAuth2Config> }) satisfies ZodType<UpsertOAuth2Config>
const validationResult = validator.safeParse(config) const validationResult = validator.safeParse(config)
@ -119,6 +137,21 @@
bind:value={data.name} bind:value={data.name}
error={errors.name} error={errors.name}
/> />
<Select
label="Authentication method*"
options={methods}
getOptionLabel={o => o.label}
getOptionValue={o => o.value}
bind:value={data.method}
error={errors.method}
/>
<div class="field-info">
<Body size="XS" color="var(--spectrum-global-color-gray-700)">
Basic will use the Authorisation Bearer header for each connection, while
Post will include the credentials in the body of the request under the
access_token property.
</Body>
</div>
<Input <Input
label="Service URL*" label="Service URL*"
placeholder="E.g. www.google.com" placeholder="E.g. www.google.com"

View File

@ -32,6 +32,7 @@ export class OAuth2Store extends BudiStore<OAuth2StoreState> {
url: c.url, url: c.url,
clientId: c.clientId, clientId: c.clientId,
clientSecret: c.clientSecret, clientSecret: c.clientSecret,
method: c.method,
})), })),
loading: false, loading: false,
})) }))

View File

@ -1,5 +1,5 @@
import Router from "@koa/router" import Router from "@koa/router"
import { PermissionType } from "@budibase/types" import { OAuth2CredentialsMethod, PermissionType } from "@budibase/types"
import { middleware } from "@budibase/backend-core" import { middleware } from "@budibase/backend-core"
import authorized from "../../middleware/authorized" import authorized from "../../middleware/authorized"
@ -13,6 +13,9 @@ function oAuth2ConfigValidator() {
url: Joi.string().required(), url: Joi.string().required(),
clientId: Joi.string().required(), clientId: Joi.string().required(),
clientSecret: Joi.string().required(), clientSecret: Joi.string().required(),
method: Joi.string()
.required()
.valid(...Object.values(OAuth2CredentialsMethod)),
}), }),
{ allowUnknown: false } { allowUnknown: false }
) )