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..2c1815f3 160000 --- a/forms-bridge/deps/http +++ b/forms-bridge/deps/http @@ -1 +1 @@ -Subproject commit 225bbf917cd8df2713398f7081f1f43afd7bafd0 +Subproject commit 2c1815f344ce4126dd8079314b79660f375c983d 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 ); +} 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',