diff --git a/bootstrap.php b/bootstrap.php index b2d6a92..d20dff2 100644 --- a/bootstrap.php +++ b/bootstrap.php @@ -8,6 +8,11 @@ 'plugins_loaded', function () { + // Unregister actions from the sso.php mu-plugin in case they exist + // This ensures that this code always takes priority for SSO handling + remove_action( 'wp_ajax_nopriv_sso-check', 'sso_check' ); + remove_action( 'wp_ajax_sso-check', 'sso_check' ); + register( [ 'name' => 'sso', diff --git a/includes/SSO_AJAX_Handler.php b/includes/SSO_AJAX_Handler.php index efa7087..f915028 100644 --- a/includes/SSO_AJAX_Handler.php +++ b/includes/SSO_AJAX_Handler.php @@ -9,7 +9,10 @@ class SSO_AJAX_Handler { */ public function __construct() { - $actions = [ SSO_Helpers::ACTION => 'login' ]; + $actions = [ + SSO_Helpers::ACTION => 'login', + SSO_Helpers_Legacy::ACTION => 'legacyLogin', + ]; foreach ( $actions as $action => $methodName ) { add_action( "wp_ajax_{$action}", [ $this, $methodName ] ); @@ -25,4 +28,15 @@ public function login() { SSO_Helpers::handleLogin( filter_input( INPUT_GET, 'token', FILTER_SANITIZE_STRING ) ); } + /** + * Handle legacy SSO login attempts. + */ + public function legacyLogin() { + + $nonce = filter_input( INPUT_GET, 'nonce', FILTER_SANITIZE_STRING ); + $salt = filter_input( INPUT_GET, 'salt', FILTER_SANITIZE_STRING ); + + SSO_Helpers_Legacy::handleLegacyLogin( $nonce, $salt ); + } + } diff --git a/includes/SSO_Helpers.php b/includes/SSO_Helpers.php index 5b071e7..663f493 100644 --- a/includes/SSO_Helpers.php +++ b/includes/SSO_Helpers.php @@ -129,6 +129,8 @@ public static function shouldThrottle() { */ public static function triggerFailure() { + self::logFailure(); + // Enable legacy action when necessary if ( has_action( 'eig_sso_fail' ) ) { do_action( 'eig_sso_fail' ); @@ -187,6 +189,20 @@ public static function getSuccessUrl() { } } + if ( $url ) { + $params = $_GET; + + unset( $params['bounce'] ); + unset( $params['nonce'] ); + unset( $params['redirect'] ); + unset( $params['salt'] ); + unset( $params['token'] ); + unset( $params['user'] ); + + // Persist all query params not used for SSO + $url .= $params ? '?' . http_build_query( $params ) : ''; + } + if ( ! $url ) { $url = apply_filters( 'newfold_sso_success_url_default', admin_url() ); } diff --git a/includes/SSO_Helpers_Legacy.php b/includes/SSO_Helpers_Legacy.php new file mode 100644 index 0000000..14dfa6c --- /dev/null +++ b/includes/SSO_Helpers_Legacy.php @@ -0,0 +1,81 @@ + 'administrator', 'number' => 1 ) ); + if ( isset( $users[0] ) && is_a( $users[0], 'WP_User' ) ) { + $user = $users[0]; + } + } + + return $user; + } + +}