Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions forms-bridge/addons/gcalendar/hooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ function ( $defaults, $addon, $schema ) {
'ref' => '#credential',
'name' => 'schema',
'type' => 'text',
'value' => 'Bearer',
'value' => 'OAuth',
),
array(
'ref' => '#credential',
Expand Down Expand Up @@ -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' => '',
Expand Down
4 changes: 2 additions & 2 deletions forms-bridge/addons/gsheets/hooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ function ( $defaults, $addon, $schema ) {
'ref' => '#credential',
'name' => 'schema',
'type' => 'text',
'value' => 'Bearer',
'value' => 'OAuth',
),
array(
'ref' => '#credential',
Expand Down Expand Up @@ -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' => '',
Expand Down
4 changes: 2 additions & 2 deletions forms-bridge/addons/slack/hooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ function ( $defaults, $addon, $schema ) {
'ref' => '#credential',
'name' => 'schema',
'type' => 'text',
'value' => 'Bearer',
'value' => 'OAuth',
),
array(
'ref' => '#credential',
Expand Down Expand Up @@ -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' => '',
Expand Down
11 changes: 3 additions & 8 deletions forms-bridge/addons/zoho/hooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ function ( $defaults, $addon, $schema ) {
'ref' => '#credential',
'name' => 'schema',
'type' => 'text',
'value' => 'Bearer',
'value' => 'OAuth',
),
array(
'ref' => '#credential',
Expand Down Expand Up @@ -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' => '',
Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion forms-bridge/deps/http
Submodule http updated from 225bbf to 2c1815
30 changes: 30 additions & 0 deletions forms-bridge/migrations/4.3.1.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php
/**
* Database migration to version 4.0.7
*
* @package formsbridge
*/

// phpcs:disable WordPress.Files.FileName

if ( ! defined( 'ABSPATH' ) ) {
exit();
}

/**
* Migration 4.3.1
*/
function forms_bridge_migration_431() {
$http = get_option( 'forms-bridge_http', array() ) ?: array(
'backends' => array(),
'credentials' => array(),
);

foreach ( $http['credentials'] as &$credential ) {
if ( 'Bearer' === $credential['schema'] ) {
$credential['schema'] = 'OAuth';
}
}

update_option( 'forms-bridge_http', $http );
}
3 changes: 2 additions & 1 deletion src/components/Backend/Authentication.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 }) {
Expand All @@ -23,7 +24,7 @@ export default function BackendAuthentication({ data = {}, setData }) {
__nextHasNoMarginBottom
/>
</FieldWrapper>
{data.schema && data.schema !== "Bearer" && (
{data.schema && data.schema !== "OAuth" && (
<FieldWrapper>
<TextControl
label={__("Client ID", "forms-bridge")}
Expand Down
23 changes: 8 additions & 15 deletions src/components/Credential/AuthorizeButton.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,27 +47,20 @@ export default function AuthorizeButton({ addon, data }) {
method: "POST",
data: { credential: data },
})
.then(({ success, redirect_url }) => {
.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 = `
<input name="client_id" value="${data.client_id}" />
<input name="response_type" value="code" />
<input name="redirect_uri" value="${restUrl("http-bridge/v1/oauth/redirect")}" />
<input name="access_type" value="offline" />
<input name="state" value="${btoa(addon)}" />
`;

if (data.scope) {
innerHTML += `<input name="scope" value="${data.scope}" />`;
}

form.innerHTML = innerHTML;
form.innerHTML = Object.keys(params).reduce((html, name) => {
const value = params[name];
if (!value) return html;
return html + `<input name="${name}" value="${value}" />`;
}, "");

form.style.visibility = "hidden";
document.body.appendChild(form);
Expand Down
25 changes: 9 additions & 16 deletions src/components/Templates/Wizard/useAuthorizedCredential.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 = `
<input name="client_id" value="${credential.client_id}" />
<input name="response_type" value="code" />
<input name="redirect_uri" value="${restUrl("http-bridge/v1/oauth/redirect")}" />
<input name="access_type" value="offline" />
<input name="state" value="${btoa(addon)}" />
`;

if (credential.scope) {
innerHTML += `<input name="scope" value="${credential.scope}" />`;
}

form.innerHTML = innerHTML;
form.innerHTML = Object.keys(params).reduce((html, name) => {
const value = params[name];
if (!value) return html;
return html + `<input name="${name}" value="${value}" />`;
}, "");

form.style.visibility = "hidden";
document.body.appendChild(form);
Expand Down
8 changes: 0 additions & 8 deletions src/lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion tests/addons/test-bigin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
2 changes: 1 addition & 1 deletion tests/addons/test-gcalendar.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
2 changes: 1 addition & 1 deletion tests/addons/test-gsheets.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
2 changes: 1 addition & 1 deletion tests/addons/test-zoho.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down