From bf45655739016a8addf5cadba72bda3acdf1b2f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lucas=20Garc=C3=ADa?= Date: Wed, 28 Jan 2026 02:54:09 +0100 Subject: [PATCH 1/4] feat: bearer credentials and pkce oauth flow --- forms-bridge/addons/gcalendar/hooks.php | 4 +-- forms-bridge/addons/gsheets/hooks.php | 4 +-- forms-bridge/addons/slack/hooks.php | 4 +-- forms-bridge/addons/zoho/hooks.php | 11 +++----- forms-bridge/deps/http | 2 +- src/components/Backend/Authentication.jsx | 3 ++- src/components/Credential/AuthorizeButton.jsx | 23 ++++++----------- .../Wizard/useAuthorizedCredential.js | 25 +++++++------------ src/lib/utils.js | 8 ------ tests/addons/test-bigin.php | 2 +- tests/addons/test-gcalendar.php | 2 +- tests/addons/test-gsheets.php | 2 +- tests/addons/test-zoho.php | 2 +- 13 files changed, 33 insertions(+), 59 deletions(-) diff --git a/forms-bridge/addons/gcalendar/hooks.php b/forms-bridge/addons/gcalendar/hooks.php index 55bdf1e1..237932a5 100644 --- a/forms-bridge/addons/gcalendar/hooks.php +++ b/forms-bridge/addons/gcalendar/hooks.php @@ -50,7 +50,7 @@ function ( $defaults, $addon, $schema ) { 'ref' => '#credential', 'name' => 'schema', 'type' => 'text', - 'value' => 'Bearer', + 'value' => 'OAuth', ), array( 'ref' => '#credential', @@ -159,7 +159,7 @@ function ( $defaults, $addon, $schema ) { ), 'credential' => array( 'name' => '', - 'schema' => 'Bearer', + 'schema' => 'OAuth', 'oauth_url' => 'https://accounts.google.com/o/oauth2/v2', 'scope' => 'https://www.googleapis.com/auth/calendar.readonly https://www.googleapis.com/auth/calendar.events', 'client_id' => '', diff --git a/forms-bridge/addons/gsheets/hooks.php b/forms-bridge/addons/gsheets/hooks.php index 1bc263d5..4bd3c509 100644 --- a/forms-bridge/addons/gsheets/hooks.php +++ b/forms-bridge/addons/gsheets/hooks.php @@ -59,7 +59,7 @@ function ( $defaults, $addon, $schema ) { 'ref' => '#credential', 'name' => 'schema', 'type' => 'text', - 'value' => 'Bearer', + 'value' => 'OAuth', ), array( 'ref' => '#credential', @@ -144,7 +144,7 @@ function ( $defaults, $addon, $schema ) { ), 'credential' => array( 'name' => '', - 'schema' => 'Bearer', + 'schema' => 'OAuth', 'oauth_url' => 'https://accounts.google.com/o/oauth2/v2', 'scope' => 'https://www.googleapis.com/auth/drive.readonly https://www.googleapis.com/auth/spreadsheets', 'client_id' => '', diff --git a/forms-bridge/addons/slack/hooks.php b/forms-bridge/addons/slack/hooks.php index 6f6ff215..c683e523 100644 --- a/forms-bridge/addons/slack/hooks.php +++ b/forms-bridge/addons/slack/hooks.php @@ -30,7 +30,7 @@ function ( $defaults, $addon, $schema ) { 'ref' => '#credential', 'name' => 'schema', 'type' => 'text', - 'value' => 'Bearer', + 'value' => 'OAuth', ), array( 'ref' => '#credential', @@ -281,7 +281,7 @@ function ( $defaults, $addon, $schema ) { ), 'credential' => array( 'name' => '', - 'schema' => 'Bearer', + 'schema' => 'OAuth', 'oauth_url' => 'https://slack.com/oauth/v2', 'scope' => 'chat:write,channels:read,users:read', 'client_id' => '', diff --git a/forms-bridge/addons/zoho/hooks.php b/forms-bridge/addons/zoho/hooks.php index a2303bb9..8d46d4cb 100644 --- a/forms-bridge/addons/zoho/hooks.php +++ b/forms-bridge/addons/zoho/hooks.php @@ -30,7 +30,7 @@ function ( $defaults, $addon, $schema ) { 'ref' => '#credential', 'name' => 'schema', 'type' => 'text', - 'value' => 'Bearer', + 'value' => 'OAuth', ), array( 'ref' => '#credential', @@ -172,7 +172,7 @@ function ( $defaults, $addon, $schema ) { ), 'credential' => array( 'name' => '', - 'schema' => 'Bearer', + 'schema' => 'OAuth', 'oauth_url' => 'https://accounts.{region}/oauth/v2', 'scope' => 'ZohoCRM.modules.ALL,ZohoCRM.settings.modules.READ,ZohoCRM.settings.layouts.READ,ZohoCRM.users.READ', 'client_id' => '', @@ -182,13 +182,8 @@ function ( $defaults, $addon, $schema ) { 'refresh_token' => '', ), 'backend' => array( + 'name' => 'Zoho API', 'base_url' => 'https://www.zohoapis.{region}', - 'headers' => array( - array( - 'name' => 'Accept', - 'value' => 'application/json', - ), - ), ), ), $defaults, diff --git a/forms-bridge/deps/http b/forms-bridge/deps/http index 225bbf91..28a82700 160000 --- a/forms-bridge/deps/http +++ b/forms-bridge/deps/http @@ -1 +1 @@ -Subproject commit 225bbf917cd8df2713398f7081f1f43afd7bafd0 +Subproject commit 28a82700bb840f4d9eafd3f93dc4785da4bac68c diff --git a/src/components/Backend/Authentication.jsx b/src/components/Backend/Authentication.jsx index 6c1a82cf..bc5d1c2c 100644 --- a/src/components/Backend/Authentication.jsx +++ b/src/components/Backend/Authentication.jsx @@ -8,6 +8,7 @@ const OPTIONS = [ { label: "Basic", value: "Basic" }, { label: "Token", value: "Token" }, { label: "Bearer", value: "Bearer" }, + { label: "OAuth", value: "OAuth" }, ]; export default function BackendAuthentication({ data = {}, setData }) { @@ -23,7 +24,7 @@ export default function BackendAuthentication({ data = {}, setData }) { __nextHasNoMarginBottom /> - {data.schema && data.schema !== "Bearer" && ( + {data.schema && data.schema !== "OAuth" && ( { + .then(({ success, data }) => { if (!success) throw "error"; + const { url, params } = data; const form = document.createElement("form"); - form.action = redirect_url; + form.action = url; form.method = "GET"; form.target = "_blank"; - let innerHTML = ` - - - - - -`; - - if (data.scope) { - innerHTML += ``; - } - - form.innerHTML = innerHTML; + form.innerHTML = Object.keys(params).reduce((html, name) => { + const value = params[name]; + if (!value) return html; + return html + ``; + }, ""); form.style.visibility = "hidden"; document.body.appendChild(form); diff --git a/src/components/Templates/Wizard/useAuthorizedCredential.js b/src/components/Templates/Wizard/useAuthorizedCredential.js index 541690cc..23874447 100644 --- a/src/components/Templates/Wizard/useAuthorizedCredential.js +++ b/src/components/Templates/Wizard/useAuthorizedCredential.js @@ -64,7 +64,7 @@ export default function useAuthorizedCredential({ data = {}, fields = [] }) { setError(false); }, [credential]); - const isOauth = data.schema === "Bearer"; + const isOauth = data.schema === "OAuth"; const authorized = useMemo(() => { if (!isOauth || !!data.refresh_token) return true; @@ -107,27 +107,20 @@ export default function useAuthorizedCredential({ data = {}, fields = [] }) { method: "POST", data: { credential }, }) - .then(({ success, redirect_url }) => { + .then(({ success, data }) => { if (!success) throw "error"; + const { url, params } = data; const form = document.createElement("form"); + form.action = url; form.method = "GET"; - form.action = redirect_url; form.target = "_blank"; - let innerHTML = ` - - - - - - `; - - if (credential.scope) { - innerHTML += ``; - } - - form.innerHTML = innerHTML; + form.innerHTML = Object.keys(params).reduce((html, name) => { + const value = params[name]; + if (!value) return html; + return html + ``; + }, ""); form.style.visibility = "hidden"; document.body.appendChild(form); diff --git a/src/lib/utils.js b/src/lib/utils.js index 46e36131..f8b61c34 100644 --- a/src/lib/utils.js +++ b/src/lib/utils.js @@ -39,14 +39,6 @@ export function validateBackend(data) { return false; } - if (data.authentication?.type) { - isValid = isValid && data.authentication.client_secret; - - if (data.authentication.type !== "Bearer") { - isValid = isValid && data.authentication.client_id; - } - } - return isValid; } diff --git a/tests/addons/test-bigin.php b/tests/addons/test-bigin.php index d7efe390..026e1793 100644 --- a/tests/addons/test-bigin.php +++ b/tests/addons/test-bigin.php @@ -68,7 +68,7 @@ public static function credentials_provider() { new Credential( array( 'name' => self::CREDENTIAL_NAME, - 'schema' => 'Bearer', + 'schema' => 'OAuth', 'client_id' => 'test-client-id', 'client_secret' => 'test-client-secret', 'region' => 'zoho.eu', diff --git a/tests/addons/test-gcalendar.php b/tests/addons/test-gcalendar.php index ef7dcd3e..6352195b 100644 --- a/tests/addons/test-gcalendar.php +++ b/tests/addons/test-gcalendar.php @@ -40,7 +40,7 @@ public static function credentials_provider() { new Credential( array( 'name' => 'gcalendar-test-credential', - 'schema' => 'Bearer', + 'schema' => 'OAuth', 'oauth_url' => 'https://accounts.google.com/o/oauth2/v2', 'client_id' => 'test-client-id', 'client_secret' => 'test-client-secret', diff --git a/tests/addons/test-gsheets.php b/tests/addons/test-gsheets.php index 8ac9b280..d695644c 100644 --- a/tests/addons/test-gsheets.php +++ b/tests/addons/test-gsheets.php @@ -47,7 +47,7 @@ public static function credentials_provider() { new Credential( array( 'name' => 'gsheets-test-credential', - 'schema' => 'Bearer', + 'schema' => 'OAuth', 'oauth_url' => 'https://accounts.google.com/o/oauth2/v2', 'client_id' => 'test-client-id', 'client_secret' => 'test-client-secret', diff --git a/tests/addons/test-zoho.php b/tests/addons/test-zoho.php index 3060d700..5b95135b 100644 --- a/tests/addons/test-zoho.php +++ b/tests/addons/test-zoho.php @@ -68,7 +68,7 @@ public static function credentials_provider() { new Credential( array( 'name' => self::CREDENTIAL_NAME, - 'schema' => 'Bearer', + 'schema' => 'OAuth', 'client_id' => 'test-client-id', 'client_secret' => 'test-client-secret', 'region' => 'zoho.eu', From d6e63bc903c3cd6d08d372f6b1ad413aa1a55b54 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lucas=20Garc=C3=ADa?= Date: Wed, 28 Jan 2026 02:56:21 +0100 Subject: [PATCH 2/4] feat: migration 4.3.1 --- forms-bridge/migrations/4.3.1.php | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 forms-bridge/migrations/4.3.1.php diff --git a/forms-bridge/migrations/4.3.1.php b/forms-bridge/migrations/4.3.1.php new file mode 100644 index 00000000..cd01fb90 --- /dev/null +++ b/forms-bridge/migrations/4.3.1.php @@ -0,0 +1,30 @@ + array(), + 'credentials' => array(), + ); + + foreach ( $http['credentials'] as &$credential ) { + if ( 'Bearer' === $credential['schema'] ) { + $credential['schema'] = 'OAuth'; + } + } + + update_option( 'forms-bridge_http', $http ); +} From 5f66ef340322ca0618f280920c40121f04656cf4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lucas=20Garc=C3=ADa?= Date: Wed, 28 Jan 2026 03:06:28 +0100 Subject: [PATCH 3/4] fix: credentials test --- forms-bridge/deps/http | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/forms-bridge/deps/http b/forms-bridge/deps/http index 28a82700..d6ace505 160000 --- a/forms-bridge/deps/http +++ b/forms-bridge/deps/http @@ -1 +1 @@ -Subproject commit 28a82700bb840f4d9eafd3f93dc4785da4bac68c +Subproject commit d6ace505cccacb6169abca7cf7d47ec517a1a7fa From 685923443995b60dba1f598afbf2ba07c569ab51 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lucas=20Garc=C3=ADa?= Date: Wed, 28 Jan 2026 03:09:07 +0100 Subject: [PATCH 4/4] fix: credentials test --- forms-bridge/deps/http | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/forms-bridge/deps/http b/forms-bridge/deps/http index d6ace505..2c1815f3 160000 --- a/forms-bridge/deps/http +++ b/forms-bridge/deps/http @@ -1 +1 @@ -Subproject commit d6ace505cccacb6169abca7cf7d47ec517a1a7fa +Subproject commit 2c1815f344ce4126dd8079314b79660f375c983d