Skip to content

Commit

Permalink
remove Auth0 related features
Browse files Browse the repository at this point in the history
  • Loading branch information
Sidsector9 committed Jul 19, 2022
1 parent e2b06b0 commit a663cad
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 190 deletions.
135 changes: 0 additions & 135 deletions includes/classes/SiteAutomation/Auth.php

This file was deleted.

41 changes: 21 additions & 20 deletions includes/classes/SiteAutomation/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,6 @@
*/
class Request {

/**
* Auth object which manages access_token.
*
* @var Auth $auth
*/
private $auth;

/**
* Site Automation API URL.
*
Expand Down Expand Up @@ -52,11 +45,8 @@ class Request {
/**
* Class constructor.
*
* @param Auth $auth Authentication object.
*/
public function __construct( $auth ) {
$this->auth = $auth;

public function __construct() {
add_action(
'sophi_retry_get_curated_data',
[ $this, 'do_cron' ],
Expand Down Expand Up @@ -213,16 +203,11 @@ private function set_status( $data ) {
* @return mixed WP_Error on failure or body request on success.
*/
private function request( $timeout ) {
$access_token = $this->auth->get_access_token();

if ( is_wp_error( $access_token ) ) {
return $access_token;
}

$args = [
'headers' => [
'Content-Type' => 'application/json',
'Authorization' => 'Bearer ' . $access_token,
'Cache-Control' => 'no-cache',
],
];

Expand Down Expand Up @@ -309,13 +294,29 @@ private function process( $response, $bypass_cache, $post_id ) {
*
* @return string
*/
private function set_api_url( $page, $widget ) {
private function set_api_url( $page = '', $widget = '' ) {
$site_automation_url = get_sophi_settings( 'site_automation_url' );
$site_automation_url = untrailingslashit( $site_automation_url );
$host = get_sophi_settings( 'host' );
$tenant_id = get_sophi_settings( 'tenant_id' );

$url = sprintf(
'%1$s/%2$s/hosts/%3$s/pages/%4$s',
$site_automation_url,
$tenant_id,
$host,
$page
);

$host = wp_parse_url( get_home_url(), PHP_URL_HOST );
if ( ! empty ( $widget ) ) {
$url = sprintf(
'%1$s/widgets/%2$s',
$url,
$widget
);
}

return sprintf( '%1$s/curatedHosts/%2$s/curator?page=%3$s&widget=%4$s', $site_automation_url, $host, $page, $widget );
return $url . '.json';
}

/**
Expand Down
3 changes: 1 addition & 2 deletions includes/classes/SiteAutomation/Services.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ class Services {
* Register services needs for Site Automation.
*/
public function register() {
$this->auth = new Auth();
$this->request = new Request( $this->auth );
$this->request = new Request();
$this->integration = new Integration( $this->request );
}

Expand Down
39 changes: 6 additions & 33 deletions includes/functions/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

namespace SophiWP\Settings;

use SophiWP\SiteAutomation\Auth;
use function SophiWP\Utils\get_domain;
use function SophiWP\Utils\is_configured;

Expand Down Expand Up @@ -156,24 +155,24 @@ function fields_setup() {
);

add_settings_field(
'client_id',
__( 'Client ID', 'sophi-wp' ),
'host',
__( 'Host', 'sophi-wp' ),
__NAMESPACE__ . '\render_input',
SETTINGS_GROUP,
'sophi_api',
[
'label_for' => 'client_id',
'label_for' => 'host',
]
);

add_settings_field(
'client_secret',
__( 'Client Secret', 'sophi-wp' ),
'tenant_id',
__( 'Tenant ID', 'sophi-wp' ),
__NAMESPACE__ . '\render_input',
SETTINGS_GROUP,
'sophi_api',
[
'label_for' => 'client_secret',
'label_for' => 'tenant_id',
]
);

Expand Down Expand Up @@ -232,8 +231,6 @@ function get_default_settings( $key = '' ) {
'environment' => $default_environment,
'collector_url' => 'collector.sophi.io',
'tracker_client_id' => get_domain(),
'client_id' => '',
'client_secret' => '',
'site_automation_url' => '',
'query_integration' => 1,
];
Expand Down Expand Up @@ -261,30 +258,6 @@ function sanitize_settings( $settings ) {

$prev_settings = get_option( SETTINGS_GROUP );

// Delete the option that holds the access token when the environment is changed
if ( ! empty( $prev_settings['environment'] ) && ! empty( $settings['environment'] ) && $prev_settings['environment'] !== $settings['environment'] ) {
delete_option( 'sophi_site_automation_access_token' );
}

if ( ! empty( $settings['client_id'] && ! empty( $settings['client_secret'] ) ) ) {
$auth = new Auth();
$auth->set_environment( $settings['environment'] );
$response = $auth->request_access_token( $settings['client_id'], $settings['client_secret'] );
if ( is_wp_error( $response ) ) {
add_settings_error(
SETTINGS_GROUP,
SETTINGS_GROUP,
$response->get_error_message()
);
}
} else {
add_settings_error(
SETTINGS_GROUP,
SETTINGS_GROUP,
__( 'Both Client ID and Client Secret are required for Site Automation integration.', 'sophi-wp' )
);
}

if ( empty( $settings['site_automation_url']) ) {
add_settings_error(
SETTINGS_GROUP,
Expand Down

0 comments on commit a663cad

Please sign in to comment.