Use new code style
This commit is contained in:
.phpcs.xml.distcomposer.jsonconstants.phpsunrise.phpuninstall.php
inc
admin-pages
class-about-admin-page.phpclass-base-admin-page.phpclass-base-customer-facing-admin-page.phpclass-broadcast-edit-admin-page.phpclass-broadcast-list-admin-page.phpclass-checkout-form-edit-admin-page.phpclass-checkout-form-list-admin-page.phpclass-customer-edit-admin-page.phpclass-customer-list-admin-page.phpclass-customizer-admin-page.phpclass-dashboard-admin-page.phpclass-discount-code-edit-admin-page.phpclass-discount-code-list-admin-page.phpclass-domain-edit-admin-page.phpclass-domain-list-admin-page.phpclass-edit-admin-page.phpclass-email-edit-admin-page.phpclass-email-list-admin-page.phpclass-email-template-customize-admin-page.phpclass-event-list-admin-page.phpclass-event-view-admin-page.phpclass-hosting-integration-wizard-admin-page.phpclass-invoice-template-customize-admin-page.phpclass-jobs-list-admin-page.phpclass-list-admin-page.phpclass-membership-edit-admin-page.phpclass-membership-list-admin-page.phpclass-migration-alert-admin-page.phpclass-payment-edit-admin-page.phpclass-payment-list-admin-page.phpclass-placeholders-admin-page.phpclass-product-edit-admin-page.phpclass-product-list-admin-page.phpclass-settings-admin-page.phpclass-setup-wizard-admin-page.phpclass-shortcodes-admin-page.phpclass-site-edit-admin-page.phpclass-site-list-admin-page.phpclass-system-info-admin-page.phpclass-tax-rates-admin-page.phpclass-template-previewer-customize-admin-page.phpclass-top-admin-nav-menu.phpclass-view-logs-admin-page.phpclass-webhook-edit-admin-page.phpclass-webhook-list-admin-page.phpclass-wizard-admin-page.php
customer-panel
class-account-admin-page.phpclass-add-new-site-admin-page.phpclass-checkout-admin-page.phpclass-my-sites-admin-page.phpclass-template-switching-admin-page.php
debug
api
builders
block-editor
checkout
class-cart.phpclass-checkout-pages.phpclass-checkout.phpclass-legacy-checkout.phpclass-line-item.php
class-admin-notices.phpclass-admin-themes-compatibility.phpclass-ajax.phpclass-api.phpclass-async-calls.phpclass-autoloader.phpclass-cron.phpclass-current.phpclass-dashboard-statistics.phpclass-dashboard-widgets.phpclass-documentation.phpclass-domain-mapping.phpclass-faker.phpclass-geolocation.phpclass-helper.phpclass-hooks.phpclass-license.phpclass-light-ajax.phpclass-logger.phpclass-maintenance-mode.phpclass-newsletter.phpclass-requirements.phpclass-scripts.phpclass-session-cookie.phpclass-settings.phpclass-sunrise.phpclass-user-switching.phpclass-views.phpclass-whitelabel.phpclass-wp-ultimo.phpsignup-fields
class-base-signup-field.phpclass-signup-field-billing-address.phpclass-signup-field-checkbox.phpclass-signup-field-color.phpclass-signup-field-discount-code.phpclass-signup-field-email.phpclass-signup-field-hidden.phpclass-signup-field-order-bump.phpclass-signup-field-order-summary.phpclass-signup-field-password.phpclass-signup-field-payment.phpclass-signup-field-period-selection.phpclass-signup-field-pricing-table.phpclass-signup-field-products.phpclass-signup-field-select.phpclass-signup-field-shortcode.phpclass-signup-field-site-title.phpclass-signup-field-site-url.phpclass-signup-field-steps.phpclass-signup-field-submit-button.phpclass-signup-field-template-selection.phpclass-signup-field-terms-of-use.phpclass-signup-field-text.phpclass-signup-field-username.php
field-templates
class-base-field-template.php
order-bump
order-summary
period-selection
pricing-table
steps
class-clean-steps-field-template.phpclass-legacy-steps-field-template.phpclass-minimal-steps-field-template.php
template-selection
compat
class-as-admin-view.phpclass-discount-code-compat.phpclass-domain-mapping-compat.phpclass-elementor-compat.phpclass-general-compat.phpclass-gutenberg-support.phpclass-legacy-shortcodes.phpclass-multiple-accounts-compat.phpclass-product-compat.php
contracts
country
class-country-br.phpclass-country-ca.phpclass-country-cn.phpclass-country-de.phpclass-country-default.phpclass-country-es.phpclass-country-fr.phpclass-country-gb.phpclass-country-in.phpclass-country-jp.phpclass-country-mx.phpclass-country-my.phpclass-country-ne.phpclass-country-nl.phpclass-country-ru.phpclass-country-sg.phpclass-country-tr.phpclass-country-us.phpclass-country-za.phpclass-country.php
database
broadcasts
checkout-forms
class-checkout-form-query.phpclass-checkout-forms-meta-table.phpclass-checkout-forms-schema.phpclass-checkout-forms-table.php
customers
class-customer-query.phpclass-customers-meta-table.phpclass-customers-schema.phpclass-customers-table.php
discount-codes
class-discount-code-query.phpclass-discount-codes-meta-table.phpclass-discount-codes-schema.phpclass-discount-codes-table.php
domains
emails
engine
class-base.phpclass-column.phpclass-compare.phpclass-date.phpclass-enum.phpclass-meta.phpclass-query.phpclass-row.phpclass-schema.phpclass-table.php
events
memberships
class-membership-query.phpclass-membership-status.phpclass-memberships-meta-table.phpclass-memberships-schema.phpclass-memberships-table.php
payments
class-payment-query.phpclass-payment-status.phpclass-payments-meta-table.phpclass-payments-schema.phpclass-payments-table.php
posts
products
class-product-query.phpclass-product-type.phpclass-products-meta-table.phpclass-products-schema.phpclass-products-table.php
sites
class-site-query.phpclass-site-type.phpclass-sites-meta-table.phpclass-sites-schema.phpclass-sites-table.php
webhooks
debug
deprecated
development
domain-mapping
duplication
exception
functions
admin.phparray-helpers.phpassets.phpbroadcast.phpcheckout-form.phpcheckout.phpcolor.phpcountries.phpcurrency.phpcustomer.phpdanger.phpdate.phpdebug.phpdiscount-code.phpdocumentation.phpdomain.phpelement.phpemail.phpenv.phpevent.phpfinancial.phpform.phpfs.phpgateway.phpgenerator.phpgeolocation.phphelper.phphttp.phpinvoice.phplegacy.phplimitations.phpmarkup-helpers.phpmembership.phpmock.phpmodel.phpnumber-helpers.phpoptions.phppages.phppayment.phpproduct.phpreflection.phprest.phpscheduler.phpsession.phpsettings.phpsite-context.phpsite.phpsort.phpstring-helpers.phpsunrise.phptax.phptemplate.phptranslation.phpurl.phpuser.phpwebhook.php
gateways
class-base-gateway.phpclass-base-stripe-gateway.phpclass-free-gateway.phpclass-ignorable-exception.phpclass-manual-gateway.phpclass-paypal-gateway.phpclass-stripe-checkout-gateway.phpclass-stripe-gateway.php
helpers
class-arr.phpclass-hash.phpclass-screenshot.phpclass-sender.phpclass-site-duplicator.phpclass-validator.phpclass-wp-config.php
validation-rules
installers
class-base-installer.phpclass-core-installer.phpclass-default-content-installer.phpclass-migrator.php
integrations
host-providers
class-base-host-provider.phpclass-closte-host-provider.phpclass-cloudflare-host-provider.phpclass-cloudways-host-provider.phpclass-cpanel-host-provider.phpclass-gridpane-host-provider.phpclass-runcloud-host-provider.phpclass-serverpilot-host-provider.phpclass-wpengine-host-provider.phpclass-wpmudev-host-provider.php
cpanel-api
internal
invoices
limitations
class-limit-customer-user-role.phpclass-limit-disk-space.phpclass-limit-domain-mapping.phpclass-limit-plugins.phpclass-limit-post-types.phpclass-limit-site-templates.phpclass-limit-sites.phpclass-limit-subtype.phpclass-limit-themes.phpclass-limit-users.phpclass-limit-visits.phpclass-limit.php
limits
class-customer-user-role-limits.phpclass-disk-space-limits.phpclass-plugin-limits.phpclass-post-type-limits.phpclass-site-template-limits.phpclass-theme-limits.phpclass-trial-limits.php
list-tables
class-base-list-table.phpclass-broadcast-list-table.phpclass-checkout-form-list-table.phpclass-customer-list-table.phpclass-customers-membership-list-table.phpclass-customers-payment-list-table.phpclass-customers-site-list-table.phpclass-discount-code-list-table.phpclass-domain-list-table.phpclass-email-list-table.phpclass-event-list-table.phpclass-inside-events-list-table.phpclass-line-item-list-table.phpclass-membership-line-item-list-table.phpclass-membership-list-table-widget.phpclass-membership-list-table.phpclass-memberships-site-list-table.phpclass-payment-line-item-list-table.phpclass-payment-list-table-widget.phpclass-payment-list-table.phpclass-product-list-table.phpclass-site-customer-list-table.phpclass-site-list-table.phpclass-sites-domain-list-table.phpclass-webhook-list-table.php
customer-panel
loaders
managers
class-base-manager.phpclass-block-manager.phpclass-broadcast-manager.phpclass-cache-manager.phpclass-checkout-form-manager.phpclass-customer-manager.phpclass-discount-code-manager.phpclass-domain-manager.phpclass-email-manager.phpclass-event-manager.phpclass-field-templates-manager.phpclass-form-manager.phpclass-gateway-manager.phpclass-job-manager.phpclass-limitation-manager.phpclass-membership-manager.phpclass-notes-manager.phpclass-notification-manager.phpclass-payment-manager.phpclass-product-manager.phpclass-signup-fields-manager.phpclass-site-manager.phpclass-visits-manager.phpclass-webhook-manager.php
models
class-base-model.phpclass-broadcast.phpclass-checkout-form.phpclass-customer.phpclass-discount-code.phpclass-domain.phpclass-email.phpclass-event.phpclass-membership.phpclass-payment.phpclass-post-base-model.phpclass-product.phpclass-site.phpclass-webhook.php
traits
objects
site-templates
sso
tax
traits
trait-singleton.phptrait-wp-ultimo-coupon-deprecated.phptrait-wp-ultimo-deprecated.phptrait-wp-ultimo-plan-deprecated.phptrait-wp-ultimo-settings-deprecated.phptrait-wp-ultimo-site-deprecated.phptrait-wp-ultimo-subscription-deprecated.php
ui
class-account-summary-element.phpclass-base-element.phpclass-billing-info-element.phpclass-checkout-element.phpclass-current-membership-element.phpclass-current-site-element.phpclass-domain-mapping-element.phpclass-field.phpclass-form.phpclass-invoices-element.phpclass-jumper.phpclass-limits-element.phpclass-login-form-element.phpclass-my-sites-element.phpclass-payment-methods-element.phpclass-simple-text-element.phpclass-site-actions-element.phpclass-site-maintenance-element.phpclass-template-previewer.phpclass-template-switching-element.phpclass-thank-you-element.phpclass-toolbox.phpclass-tours.php
updater
tests
Admin_Pages
Gateway_Functions_Test.phpWP_Ultimo
WP_Ultimo_Test.phpbootstrap.phpviews
about.phpadmin-notices.php
wp-multisite-waas.phpadmin-pages
fields
field-code-editor.phpfield-color-picker.phpfield-dashicon.phpfield-group.phpfield-header.phpfield-hidden.phpfield-html.phpfield-image.phpfield-link.phpfield-multiselect.phpfield-note.phpfield-repeater.phpfield-select-icon.phpfield-select.phpfield-small-header.phpfield-submit.phpfield-tab-select.phpfield-text-display.phpfield-text-edit.phpfield-text.phpfield-textarea.phpfield-toggle.phpfield-wp-editor.phpform.php
partials
base
centered.php
checkout-forms
customers
dash.phpedit.phpedit
empty-state.phpfilter.phpgrid.phplist.phpproducts
responsive-table-row.phpsettings.phpsites
wizard.phpwizard
broadcast
checkout
confirmation.php
fields
field-checkbox-multi.phpfield-checkbox.phpfield-group.phpfield-hidden.phpfield-html.phpfield-note.phpfield-password.phpfield-payment-methods.phpfield-products.phpfield-radio.phpfield-select.phpfield-submit.phpfield-text.phpfield-toggle.phpform.php
form.phppartials
partials
paypal
register.phptemplates
order-bump
order-summary
period-selection
pricing-table
steps
template-selection
customers
dashboard-statistics
filter.phpwidget-countries.phpwidget-forms.phpwidget-most-visited-sites.phpwidget-mrr-growth.phpwidget-new-accounts.phpwidget-revenue.phpwidget-tax-by-code.phpwidget-tax-by-day.phpwidget-tax-graph.phpwidget-taxes.php
dashboard-widgets
account-summary.phpactivity-stream.phpbilling-info.phpcurrent-membership-product-details.phpcurrent-membership.phpcurrent-site.phpdomain-mapping.phpfirst-steps.phpinvoices.phplimits-and-quotas.phplogin-additional-forms.phplogin-form.phpmy-sites.phpsimple-text.phpsite-actions.phpsite-maintenance.phpsummary.phpthank-you.php
domain
dynamic-styles
emails
admin
customer
events
invoice
legacy
signup
limitations
memberships
payments
settings
fields
shortcodes
sites
system-info
taxes
ui
branding
container-toggle.phpjumper-trigger.phpjumper.phpselectize-templates.phptemplate-previewer.phptoolbox.phpwizards
@@ -15,17 +15,15 @@
|
||||
|
||||
namespace WP_Ultimo\SSO;
|
||||
|
||||
use \WP_Ultimo\Helpers\Hash;
|
||||
use \Jasny\SSO\Server\Server;
|
||||
use \Jasny\SSO\Server\ServerException;
|
||||
use \Jasny\SSO\Server\BrokerException;
|
||||
use \Jasny\SSO\Broker\NotAttachedException;
|
||||
use \Nyholm\Psr7\Factory\Psr17Factory;
|
||||
use \Symfony\Component\Cache\Adapter\FilesystemAdapter;
|
||||
use \Symfony\Component\Cache\Psr16Cache;
|
||||
|
||||
// Exit if accessed directly
|
||||
defined('ABSPATH') || exit;
|
||||
use Exception;
|
||||
use WP_Ultimo\Helpers\Hash;
|
||||
use Jasny\SSO\Server\Server;
|
||||
use Jasny\SSO\Server\ServerException;
|
||||
use Jasny\SSO\Server\BrokerException;
|
||||
use Jasny\SSO\Broker\NotAttachedException;
|
||||
use Nyholm\Psr7\Factory\Psr17Factory;
|
||||
use Symfony\Component\Cache\Adapter\FilesystemAdapter;
|
||||
use Symfony\Component\Cache\Psr16Cache;
|
||||
|
||||
/**
|
||||
* Handles Sign-sign on.
|
||||
@@ -74,10 +72,8 @@ class SSO {
|
||||
* @return void
|
||||
*/
|
||||
public function init() {
|
||||
|
||||
$this->is_enabled() && $this->startup();
|
||||
|
||||
} // end init;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the status of SSO.
|
||||
@@ -90,10 +86,8 @@ class SSO {
|
||||
$enabled = $this->get_setting('enable_sso', true);
|
||||
|
||||
if (has_filter('mercator.sso.enabled')) {
|
||||
|
||||
$enabled = apply_filters_deprecated('mercator.sso.enabled', $enabled, '2.0.0', 'wu_sso_enabled');
|
||||
|
||||
} // end if;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable/disable cross-domain single-sign-on capability.
|
||||
@@ -106,8 +100,7 @@ class SSO {
|
||||
* @return bool If SSO is enabled or not.
|
||||
*/
|
||||
return apply_filters('wu_sso_enabled', $enabled);
|
||||
|
||||
} // end is_enabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* Encode a given string.
|
||||
@@ -119,10 +112,8 @@ class SSO {
|
||||
* @return string The hashed content.
|
||||
*/
|
||||
public function encode($content, $salt) {
|
||||
|
||||
return Hash::encode($content, $salt);
|
||||
|
||||
} // end encode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Decode a given string.
|
||||
@@ -134,10 +125,8 @@ class SSO {
|
||||
* @return string The original content.
|
||||
*/
|
||||
public function decode($hash, $salt) {
|
||||
|
||||
return Hash::decode($hash, $salt);
|
||||
|
||||
} // end decode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current url.
|
||||
@@ -146,41 +135,33 @@ class SSO {
|
||||
* @return string
|
||||
*/
|
||||
public function get_current_url() {
|
||||
|
||||
return wu_get_current_url();
|
||||
|
||||
} // end get_current_url;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the content of a key inside the $_REQUEST array.
|
||||
*
|
||||
* @since 2.0.11
|
||||
*
|
||||
* @param string $key The key to retrieve.
|
||||
* @param mixed $default The default content.
|
||||
* @param mixed $default_content The default content.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function input($key, $default = false) {
|
||||
|
||||
return wu_request($key, $default);
|
||||
|
||||
} // end input;
|
||||
public function input($key, $default_content = false) {
|
||||
return wu_request($key, $default_content);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the content of a array key, if it exists.
|
||||
* Returns the content of an array key, if it exists.
|
||||
*
|
||||
* @since 2.0.11
|
||||
*
|
||||
* @param array $array The array to check.
|
||||
* @param array $array_checked The array to check.
|
||||
* @param string $key The key to test and return.
|
||||
* @param mixed $default The default content to return.
|
||||
* @param mixed $default_value The default content to return.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function get_isset($array, $key, $default = false) {
|
||||
|
||||
return wu_get_isset($array, $key, $default);
|
||||
|
||||
} // end get_isset;
|
||||
public function get_isset($array_checked, $key, $default_value = false) {
|
||||
return wu_get_isset($array_checked, $key, $default_value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get settings and preferences.
|
||||
@@ -188,14 +169,12 @@ class SSO {
|
||||
* @since 2.0.11
|
||||
*
|
||||
* @param string $key The setting to retrieve.
|
||||
* @param mixed $default The default value to return, if no setting is found.
|
||||
* @param mixed $default_value The default value to return, if no setting is found.
|
||||
* @return mixed
|
||||
*/
|
||||
public function get_setting($key, $default = false) {
|
||||
|
||||
return wu_get_setting($key, $default);
|
||||
|
||||
} // end get_setting;
|
||||
public function get_setting($key, $default_value = false) {
|
||||
return wu_get_setting($key, $default_value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Startup the SSO hooks and filters.
|
||||
@@ -302,8 +281,7 @@ class SSO {
|
||||
* on init, so later functionality can also hook into it.
|
||||
*/
|
||||
add_action('init', array($this, 'loaded_on_init'));
|
||||
|
||||
} // end startup;
|
||||
}
|
||||
|
||||
/**
|
||||
* Late loaded hook, triggered on init.
|
||||
@@ -312,10 +290,8 @@ class SSO {
|
||||
* @return void
|
||||
*/
|
||||
public function loaded_on_init() {
|
||||
|
||||
do_action('wu_sso_loaded_on_init', $this);
|
||||
|
||||
} // end loaded_on_init;
|
||||
}
|
||||
|
||||
/**
|
||||
* Changes the default WordPress requirements for setting the logged in cookie
|
||||
@@ -327,10 +303,8 @@ class SSO {
|
||||
* @return boolean
|
||||
*/
|
||||
public function force_secure_login_cookie() {
|
||||
|
||||
return is_ssl();
|
||||
|
||||
} // end force_secure_login_cookie;
|
||||
}
|
||||
|
||||
/**
|
||||
* Bypasses the auth redirect on the wp-admin side of things.
|
||||
@@ -349,15 +323,12 @@ class SSO {
|
||||
|
||||
$broker = $this->get_broker();
|
||||
|
||||
if (!$broker) {
|
||||
|
||||
} // end if;
|
||||
if ( ! $broker) {
|
||||
}
|
||||
|
||||
if ($broker->is_must_redirect_call()) {
|
||||
|
||||
return false;
|
||||
|
||||
} // end if;
|
||||
}
|
||||
|
||||
$sso_path = $this->get_url_path();
|
||||
|
||||
@@ -369,10 +340,8 @@ class SSO {
|
||||
* login redirect.
|
||||
*/
|
||||
if ($this->input($sso_path) && $this->input($sso_path) !== 'done') {
|
||||
|
||||
return true;
|
||||
|
||||
} // end if;
|
||||
}
|
||||
|
||||
$should_skip_redirect = $this->get_isset($_COOKIE, 'wu_sso_denied', false);
|
||||
|
||||
@@ -385,23 +354,24 @@ class SSO {
|
||||
* 2. If the user is logged in or not;
|
||||
* 3. If we should skip the redirect, based on previous attempts.
|
||||
*/
|
||||
if (!wu_is_same_domain() && !is_user_logged_in() && !$should_skip_redirect) {
|
||||
|
||||
if ( ! wu_is_same_domain() && ! is_user_logged_in() && ! $should_skip_redirect) {
|
||||
nocache_headers();
|
||||
|
||||
$test = get_admin_url();
|
||||
|
||||
$redirect_after = $pagenow === 'index.php' ? '' : $this->get_current_url();
|
||||
$redirect_after = 'index.php' === $pagenow ? '' : $this->get_current_url();
|
||||
|
||||
$redirect_url = add_query_arg(array(
|
||||
$sso_path => 'login'
|
||||
), wp_login_url($redirect_after));
|
||||
$redirect_url = add_query_arg(
|
||||
array(
|
||||
$sso_path => 'login',
|
||||
),
|
||||
wp_login_url($redirect_after)
|
||||
);
|
||||
|
||||
wp_redirect($redirect_url);
|
||||
|
||||
exit;
|
||||
|
||||
} // end if;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fix the redirect URL, just to be sure
|
||||
@@ -409,9 +379,12 @@ class SSO {
|
||||
*
|
||||
* @since 2.0.11
|
||||
*/
|
||||
$_SERVER['REQUEST_URI'] = str_replace('https://a.com/', '', remove_query_arg('sso', 'https://a.com/' . $_SERVER['REQUEST_URI']));
|
||||
|
||||
} // end handle_auth_redirect;
|
||||
$_SERVER['REQUEST_URI'] = str_replace(
|
||||
'https://a.com/',
|
||||
'',
|
||||
remove_query_arg('sso', 'https://a.com/' . $_SERVER['REQUEST_URI'])
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Listens for SSO requests and route them to the correct handler.
|
||||
@@ -423,11 +396,9 @@ class SSO {
|
||||
|
||||
$action = $this->get_sso_action();
|
||||
|
||||
if (!$action) {
|
||||
|
||||
if ( ! $action) {
|
||||
return;
|
||||
|
||||
} // end if;
|
||||
}
|
||||
|
||||
header('Access-Control-Allow-Headers: Content-Type');
|
||||
|
||||
@@ -444,8 +415,7 @@ class SSO {
|
||||
do_action('wu_sso_handle', $action, $return_type, $this);
|
||||
|
||||
do_action("wu_sso_handle_{$action}", $return_type, $this);
|
||||
|
||||
} // end handle_requests;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles the SSO server side of the auth protocol.
|
||||
@@ -462,45 +432,36 @@ class SSO {
|
||||
$server = $this->get_server();
|
||||
|
||||
try {
|
||||
|
||||
$verification_code = $server->attach();
|
||||
$error = null;
|
||||
|
||||
} catch (Exception\SSO_Session_Exception $e) {
|
||||
|
||||
if (is_ssl()) {
|
||||
|
||||
$verification_code = null;
|
||||
|
||||
$error = array(
|
||||
'code' => $e->getCode(),
|
||||
'message' => $e->getMessage(),
|
||||
);
|
||||
|
||||
} else {
|
||||
|
||||
$verification_code = 'must-redirect';
|
||||
|
||||
} // end if;
|
||||
|
||||
}
|
||||
} catch (\Throwable $th) {
|
||||
|
||||
$verification_code = null;
|
||||
|
||||
$error = array(
|
||||
'code' => $th->getCode(),
|
||||
'message' => $th->getMessage(),
|
||||
);
|
||||
}
|
||||
|
||||
} // end try;
|
||||
|
||||
if ($response_type === 'jsonp') {
|
||||
|
||||
$data = json_encode($error ?? array( // phpcs:ignore
|
||||
'code' => 200,
|
||||
'verify' => $verification_code,
|
||||
'return_url' => $this->input('return_url', ''),
|
||||
));
|
||||
if ('jsonp' === $response_type) {
|
||||
$data = wp_json_encode(
|
||||
$error ?? array( // phpcs:ignore
|
||||
'code' => 200,
|
||||
'verify' => $verification_code,
|
||||
'return_url' => $this->input('return_url', ''),
|
||||
)
|
||||
);
|
||||
|
||||
$response_code = 200; // phpcs:ignore
|
||||
|
||||
@@ -509,18 +470,14 @@ class SSO {
|
||||
status_header($response_code);
|
||||
|
||||
exit;
|
||||
|
||||
} elseif ($response_type === 'redirect') {
|
||||
|
||||
$args = array(
|
||||
'sso_verify' => $verification_code ? $verification_code : 'invalid',
|
||||
);
|
||||
|
||||
if (isset($error) && $error) {
|
||||
|
||||
$args['sso_error'] = $error['message'];
|
||||
|
||||
} // end if;
|
||||
}
|
||||
|
||||
$return_url = remove_query_arg('sso_verify', $_GET['return_url']);
|
||||
|
||||
@@ -529,10 +486,8 @@ class SSO {
|
||||
wp_redirect($url, 303, 'WP-Ultimo-SSO');
|
||||
|
||||
exit;
|
||||
|
||||
} // end if;
|
||||
|
||||
} // end handle_server;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles the broker side of the SSO protocol.
|
||||
@@ -545,16 +500,12 @@ class SSO {
|
||||
public function handle_broker($response_type = 'redirect') {
|
||||
|
||||
if (is_main_site()) {
|
||||
|
||||
return;
|
||||
|
||||
} // end if;
|
||||
}
|
||||
|
||||
if (is_user_logged_in()) {
|
||||
|
||||
return;
|
||||
|
||||
} // end if;
|
||||
}
|
||||
|
||||
nocache_headers();
|
||||
|
||||
@@ -563,7 +514,6 @@ class SSO {
|
||||
$verify_code = $this->input('sso_verify');
|
||||
|
||||
if ($verify_code) {
|
||||
|
||||
$broker->verify($verify_code);
|
||||
|
||||
$url = $this->input('return_url', $this->get_current_url());
|
||||
@@ -573,43 +523,37 @@ class SSO {
|
||||
wp_redirect($redirect_url, 302, 'WP-Ultimo-SSO');
|
||||
|
||||
exit;
|
||||
}
|
||||
|
||||
} // end if;
|
||||
|
||||
// Attach through redirect if the client isn't attached yet.
|
||||
if (!$broker->isAttached()) {
|
||||
|
||||
// Attach through redirect if the client isn't attached yet.
|
||||
if ( ! $broker->isAttached()) {
|
||||
$return_url = $this->get_current_url();
|
||||
|
||||
if ($response_type === 'jsonp') {
|
||||
|
||||
$attach_url = $broker->getAttachUrl(array(
|
||||
'_jsonp' => '1',
|
||||
));
|
||||
|
||||
if ( 'jsonp' === $response_type) {
|
||||
$attach_url = $broker->getAttachUrl(
|
||||
array(
|
||||
'_jsonp' => '1',
|
||||
)
|
||||
);
|
||||
} else {
|
||||
|
||||
$attach_url = $broker->getAttachUrl(array(
|
||||
'return_url' => $return_url,
|
||||
));
|
||||
|
||||
} // end if;
|
||||
$attach_url = $broker->getAttachUrl(
|
||||
array(
|
||||
'return_url' => $return_url,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
wp_redirect($attach_url, 302, 'WP-Ultimo-SSO');
|
||||
|
||||
exit();
|
||||
|
||||
} // end if;
|
||||
}
|
||||
|
||||
if ($response_type === 'jsonp') {
|
||||
|
||||
echo '// Nothing to see here.';
|
||||
|
||||
exit;
|
||||
|
||||
} // end if;
|
||||
|
||||
} // end handle_broker;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Filters the list of allowed origins to add
|
||||
@@ -632,41 +576,38 @@ class SSO {
|
||||
|
||||
$origin_url = wp_parse_url(get_http_origin());
|
||||
|
||||
$sites = get_sites(array(
|
||||
'network_id' => get_current_network_id(),
|
||||
'domain' => $this->get_isset($origin_url, 'host', 'invalid'),
|
||||
));
|
||||
$sites = get_sites(
|
||||
array(
|
||||
'network_id' => get_current_network_id(),
|
||||
'domain' => $this->get_isset($origin_url, 'host', 'invalid'),
|
||||
)
|
||||
);
|
||||
|
||||
if ($sites) {
|
||||
|
||||
$additional_domains[] = sprintf('http://%s', $this->get_isset($origin_url, 'host', 'invalid'));
|
||||
$additional_domains[] = sprintf('https://%s', $this->get_isset($origin_url, 'host', 'invalid'));
|
||||
|
||||
} // end if;
|
||||
}
|
||||
|
||||
$site = get_site_by_path($this->get_isset($origin_url, 'host', 'invalid'), $this->get_isset($origin_url, 'path', '/'));
|
||||
|
||||
if ($site) {
|
||||
|
||||
$domains = wu_get_domains(array(
|
||||
'active' => true,
|
||||
'blog_id' => $site->blog_id,
|
||||
'stage__not_in' => \WP_Ultimo\Models\Domain::INACTIVE_STAGES,
|
||||
'fields' => 'domain',
|
||||
));
|
||||
$domains = wu_get_domains(
|
||||
array(
|
||||
'active' => true,
|
||||
'blog_id' => $site->blog_id,
|
||||
'stage__not_in' => \WP_Ultimo\Models\Domain::INACTIVE_STAGES,
|
||||
'fields' => 'domain',
|
||||
)
|
||||
);
|
||||
|
||||
foreach ($domains as $domain) {
|
||||
|
||||
$additional_domains[] = "http://{$domain}";
|
||||
$additional_domains[] = "https://{$domain}";
|
||||
|
||||
} // end foreach;
|
||||
|
||||
} // end if;
|
||||
}
|
||||
}
|
||||
|
||||
return array_merge($allowed_origins, $additional_domains);
|
||||
|
||||
} // end add_additional_origins;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines the current user based on the Bearer token received.
|
||||
@@ -682,16 +623,13 @@ class SSO {
|
||||
|
||||
$sso_path = $this->get_url_path();
|
||||
|
||||
if (!$this->input($sso_path) || $this->input($sso_path) !== 'done') {
|
||||
|
||||
if ( ! $this->input($sso_path) || $this->input($sso_path) !== 'done') {
|
||||
return $current_user_id;
|
||||
|
||||
} // end if;
|
||||
}
|
||||
|
||||
$broker = $this->get_broker();
|
||||
|
||||
try {
|
||||
|
||||
$bearer = $broker->getBearerToken();
|
||||
|
||||
$server_request = $this->build_server_request('GET', $this->get_current_url())->withHeader('Authorization', "Bearer $bearer");
|
||||
@@ -699,23 +637,16 @@ class SSO {
|
||||
$this->get_server()->startBrokerSession($server_request);
|
||||
|
||||
if ($this->get_target_user_id()) {
|
||||
|
||||
wp_set_auth_cookie($this->get_target_user_id(), true);
|
||||
|
||||
if ($pagenow === 'wp-login.php') {
|
||||
|
||||
if ('wp-login.php' === $pagenow) {
|
||||
wp_redirect(wu_request('redirect_to', get_admin_url()));
|
||||
|
||||
exit;
|
||||
|
||||
} // end if;
|
||||
}
|
||||
|
||||
return $this->get_target_user_id();
|
||||
|
||||
} // end if;
|
||||
|
||||
}
|
||||
} catch (\Throwable $exception) {
|
||||
|
||||
/**
|
||||
* We don't need to handle the exceptions here
|
||||
* as we mostly just want to ignore this and move
|
||||
@@ -726,12 +657,9 @@ class SSO {
|
||||
* @throws BrokerException
|
||||
* @throws NotAttachedException
|
||||
*/
|
||||
|
||||
} // end try;
|
||||
|
||||
}
|
||||
return $current_user_id;
|
||||
|
||||
} // end determine_current_user;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a user determined by a bearer into a cookie-based auth.
|
||||
@@ -744,16 +672,13 @@ class SSO {
|
||||
$broker = $this->get_broker();
|
||||
|
||||
if (is_user_logged_in() && $broker && $broker->isAttached()) {
|
||||
|
||||
$broker->clearToken();
|
||||
|
||||
$id = $this->decode($broker->getBrokerId(), $this->salt());
|
||||
|
||||
delete_site_transient(sprintf('sso-%s-%s', $broker->getBrokerId(), $id));
|
||||
|
||||
} // end if;
|
||||
|
||||
} // end convert_bearer_into_auth_cookies;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the SSO tags to the removable query args.
|
||||
@@ -768,8 +693,7 @@ class SSO {
|
||||
$removable_query_args[] = $this->get_url_path();
|
||||
|
||||
return $removable_query_args;
|
||||
|
||||
} // end add_sso_removable_query_args;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the front-end script to trigger SSO flows
|
||||
@@ -780,32 +704,22 @@ class SSO {
|
||||
*/
|
||||
public function enqueue_script() {
|
||||
|
||||
global $pagenow;
|
||||
|
||||
if (is_main_site()) {
|
||||
|
||||
return;
|
||||
|
||||
} // end if;
|
||||
}
|
||||
|
||||
if ($this->get_setting('restrict_sso_to_login_pages', false)) {
|
||||
|
||||
if (wu_is_login_page() === false) {
|
||||
|
||||
return;
|
||||
|
||||
} // end if;
|
||||
|
||||
} // end if;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* The visitor is actively trying to logout. Let them do it!
|
||||
*/
|
||||
if ($this->input('action', 'nothing') === 'logout' || $this->input('loggedout')) {
|
||||
|
||||
return;
|
||||
|
||||
} // end if;
|
||||
}
|
||||
|
||||
wp_register_script('wu-detect-incognito', wu_get_asset('detectincognito.js', 'js/lib'), false, wu_get_version());
|
||||
|
||||
@@ -834,8 +748,7 @@ class SSO {
|
||||
wp_localize_script('wu-sso', 'wu_sso_config', $options);
|
||||
|
||||
wp_enqueue_script('wu-sso');
|
||||
|
||||
} // end enqueue_script;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the strategy to be used by default.
|
||||
@@ -853,18 +766,13 @@ class SSO {
|
||||
$env = 'development';
|
||||
|
||||
if (function_exists('wp_get_environment_type')) {
|
||||
|
||||
$env = wp_get_environment_type();
|
||||
|
||||
} else {
|
||||
|
||||
$env = defined('WP_DEBUG') && WP_DEBUG ? 'development' : 'production';
|
||||
}
|
||||
|
||||
} // end if;
|
||||
|
||||
return apply_filters('wu_sso_get_strategy', $env === 'development' ? 'redirect' : 'ajax', $env, $this);
|
||||
|
||||
} // end get_strategy;
|
||||
return apply_filters('wu_sso_get_strategy', 'development' === $env ? 'redirect' : 'ajax', $env, $this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the final return URL.
|
||||
@@ -881,10 +789,8 @@ class SSO {
|
||||
$query_values = array();
|
||||
|
||||
if (isset($parsed_url['query'])) {
|
||||
|
||||
parse_str($parsed_url['query'], $query_values);
|
||||
|
||||
} // end if;
|
||||
}
|
||||
|
||||
$sso_path = $this->get_url_path();
|
||||
|
||||
@@ -902,17 +808,14 @@ class SSO {
|
||||
);
|
||||
|
||||
if (isset($query_values['redirect_to'])) {
|
||||
|
||||
$args['redirect_to'] = urlencode($query_values['redirect_to']);
|
||||
|
||||
} // end if;
|
||||
$args['redirect_to'] = rawurlencode($query_values['redirect_to']);
|
||||
}
|
||||
|
||||
// We should use the login URL to avoid cache issues.
|
||||
$login_url = wp_login_url(wu_get_isset($query_values, 'redirect_to', implode('/', $fragments)));
|
||||
|
||||
return add_query_arg($args, $login_url);
|
||||
|
||||
} // end get_final_return_url;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the return type we need to use.
|
||||
@@ -931,8 +834,7 @@ class SSO {
|
||||
$received_type = $this->input('return_type', 'redirect');
|
||||
|
||||
return in_array($received_type, $allowed_return_types, true) ? $received_type : 'redirect';
|
||||
|
||||
} // end get_return_type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses the request and gets the SSO action to perform.
|
||||
@@ -954,27 +856,19 @@ class SSO {
|
||||
|
||||
$action = $this->get_isset($m, 0, '');
|
||||
|
||||
if (!$action) {
|
||||
|
||||
if ( ! $action) {
|
||||
$action = $this->input($sso_path, 'done') !== 'done' ? $sso_path : '';
|
||||
|
||||
} // end if;
|
||||
|
||||
if (!$action) {
|
||||
|
||||
}
|
||||
if ( ! $action) {
|
||||
$action = $this->input("$sso_path-grant", 'done') !== 'done' ? "$sso_path-grant" : '';
|
||||
}
|
||||
|
||||
} // end if;
|
||||
|
||||
if (!$action) {
|
||||
|
||||
if ( ! $action) {
|
||||
$action = $this->input("{$sso_path}_verify", '') !== '' ? $sso_path : '';
|
||||
|
||||
} // end if;
|
||||
}
|
||||
|
||||
return $action;
|
||||
|
||||
} // end get_sso_action;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the salt to be used on the hashing functions.
|
||||
@@ -983,10 +877,8 @@ class SSO {
|
||||
* @return string
|
||||
*/
|
||||
public function salt() {
|
||||
|
||||
return apply_filters('wu_sso_salt', wp_salt(), $this);
|
||||
|
||||
} // end salt;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a PSR16-compatible cache implementation.
|
||||
@@ -996,18 +888,15 @@ class SSO {
|
||||
*/
|
||||
public function cache() {
|
||||
|
||||
if ($this->cache === null) {
|
||||
|
||||
if (null === $this->cache) {
|
||||
// the PSR-6 cache object that you want to use
|
||||
$psr6_cache = new FilesystemAdapter();
|
||||
|
||||
$this->cache = new Psr16Cache($psr6_cache);
|
||||
|
||||
} // end if;
|
||||
}
|
||||
|
||||
return apply_filters('wu_sso_cache', $this->cache, $this);
|
||||
|
||||
} // end cache;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a PSR7 Server Request object.
|
||||
@@ -1024,8 +913,7 @@ class SSO {
|
||||
$request = $psr7_server_request_builder->createServerRequest('GET', $url);
|
||||
|
||||
return apply_filters('wu_sso_server_request', $request, $url, $this);
|
||||
|
||||
} // end build_server_request;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a PSR3 logger interface that we can use to log SSO results.
|
||||
@@ -1035,13 +923,10 @@ class SSO {
|
||||
*/
|
||||
public function logger() {
|
||||
|
||||
if ($this->logger === null) {
|
||||
|
||||
if (null === $this->logger) {
|
||||
return apply_filters('wu_sso_logger', $this->logger, $this);
|
||||
|
||||
} // end if;
|
||||
|
||||
} // end logger;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a secret based on the date of registration of a sub-site.
|
||||
@@ -1050,24 +935,20 @@ class SSO {
|
||||
*
|
||||
* @param string $date The date to use.
|
||||
* @return string The hashed secret.
|
||||
* @throws Exception\SSO_Exception Failure.
|
||||
*/
|
||||
public function calculate_secret_from_date($date) {
|
||||
|
||||
$tz = new \DateTimeZone('GMT');
|
||||
|
||||
try {
|
||||
|
||||
$int_version = (int) \DateTime::createFromFormat('Y-m-d H:i:s', $date, $tz)->format('mdisY');
|
||||
|
||||
} catch (\Throwable $exception) {
|
||||
|
||||
throw new Exception\SSO_Exception(__('SSO secret creation failed.', 'wp-ultimo'), 500);
|
||||
|
||||
} // end try;
|
||||
}
|
||||
|
||||
return wp_hash($int_version);
|
||||
|
||||
} // end calculate_secret_from_date;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the server object to be used on the SSO protocol.
|
||||
@@ -1082,8 +963,7 @@ class SSO {
|
||||
$server = (new Server(array($this, 'get_broker_by_id'), $this->cache()))->withSession($session_handler);
|
||||
|
||||
return apply_filters('wu_sso_get_server', $server, $this);
|
||||
|
||||
} // end get_server;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a sub-site based on the broker id passed.
|
||||
@@ -1101,11 +981,9 @@ class SSO {
|
||||
|
||||
$site = get_site($site_id ? $site_id : 'non-existent');
|
||||
|
||||
if (!$site) {
|
||||
|
||||
if ( ! $site) {
|
||||
return null;
|
||||
|
||||
} // end if;
|
||||
}
|
||||
|
||||
$main_domain = wp_parse_url(get_home_url($site_id), PHP_URL_HOST);
|
||||
|
||||
@@ -1115,10 +993,8 @@ class SSO {
|
||||
);
|
||||
|
||||
if (is_subdomain_install()) {
|
||||
|
||||
$domain_list[] = $site->domain;
|
||||
|
||||
} // end if;
|
||||
}
|
||||
|
||||
$domain_list = apply_filters('wu_sso_site_allowed_domains', $domain_list, $site_id, $site, $this);
|
||||
|
||||
@@ -1126,8 +1002,7 @@ class SSO {
|
||||
'secret' => $this->calculate_secret_from_date($site->registered),
|
||||
'domains' => $domain_list,
|
||||
);
|
||||
|
||||
} // end get_broker_by_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a broker instance.
|
||||
@@ -1148,8 +1023,7 @@ class SSO {
|
||||
$this->broker = new SSO_Broker($home_sso_url, $broker_id, $secret);
|
||||
|
||||
return apply_filters('wu_sso_get_broker', $this->broker, $this);
|
||||
|
||||
} // end get_broker;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the target user after the bearer is passed.
|
||||
@@ -1160,10 +1034,8 @@ class SSO {
|
||||
* @return void
|
||||
*/
|
||||
public function set_target_user_id($target_user_id) {
|
||||
|
||||
$this->target_user_id = $target_user_id;
|
||||
|
||||
} // end set_target_user_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the target user id.
|
||||
@@ -1172,10 +1044,8 @@ class SSO {
|
||||
* @return int
|
||||
*/
|
||||
public function get_target_user_id() {
|
||||
|
||||
return $this->target_user_id;
|
||||
|
||||
} // end get_target_user_id;
|
||||
}
|
||||
/**
|
||||
* Get the url path for SSO.
|
||||
*
|
||||
@@ -1194,14 +1064,11 @@ class SSO {
|
||||
);
|
||||
|
||||
if ($action) {
|
||||
|
||||
$fragments[] = $action;
|
||||
|
||||
} // end if;
|
||||
}
|
||||
|
||||
return implode('-', $fragments);
|
||||
|
||||
} // end get_url_path;
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function to generate a sso url.
|
||||
@@ -1213,13 +1080,11 @@ class SSO {
|
||||
*/
|
||||
public static function with_sso($url) {
|
||||
|
||||
$sso = SSO::get_instance();
|
||||
$sso = self::get_instance();
|
||||
|
||||
if ($sso->is_enabled() === false) {
|
||||
|
||||
return $url;
|
||||
|
||||
} // end if;
|
||||
}
|
||||
|
||||
$sso_path = $sso->get_url_path();
|
||||
|
||||
@@ -1228,7 +1093,5 @@ class SSO {
|
||||
);
|
||||
|
||||
return add_query_arg($sso_params, $url);
|
||||
|
||||
} // end with_sso;
|
||||
|
||||
} // end class SSO;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user