diff --git a/plugins/bcc-login/includes/class-bcc-login-client.php b/plugins/bcc-login/includes/class-bcc-login-client.php index ed84654..45b38f9 100644 --- a/plugins/bcc-login/includes/class-bcc-login-client.php +++ b/plugins/bcc-login/includes/class-bcc-login-client.php @@ -49,7 +49,7 @@ private function create_authentication_state() : Auth_State{ // New state w/ timestamp. $obj_state = new Auth_State(); $obj_state->state = md5( openssl_random_pseudo_bytes(16) . microtime( true ) ); - $obj_state->return_url = $this->get_current_url(); + $obj_state->return_url = $this->get_redirect_url(); set_transient( 'oidc_auth_state_' . $obj_state->state, $obj_state, $this->STATE_TIME_LIMIT ); return $obj_state; @@ -270,22 +270,17 @@ private function get_full_redirect_url() { private function get_current_url() { global $wp; + return add_query_arg( $_SERVER['QUERY_STRING'], '', home_url( $_SERVER['REQUEST_URI']) ); + } + + private function get_redirect_url() { if(isset($_GET['redirect_to'])) { if( $this->parse_url_origin($_GET['redirect_to']) !== $this->parse_url_origin(site_url()) ) { return "/"; } - return $_GET['redirect_to']; } - - // If the Permalink Structure is set to Plain we use the old solution with $_SERVER - if( get_option('permalink_structure') != "") { - return add_query_arg( $_SERVER['QUERY_STRING'], '', home_url( $wp->request ) ); - } - else { - // We replace 'wp-login.php' to 'wp-admin' to avoid the redirect loop when logging through SSO directly to the admin dashboard - return $_SERVER['REQUEST_SCHEME'] . '://' . $_SERVER['HTTP_HOST'] . str_replace('wp-login.php', 'wp-admin', $_SERVER['REQUEST_URI']); - } + return str_replace('wp-login.php', '', $this->get_current_url()); } private function parse_url_origin($url) { diff --git a/plugins/bcc-login/includes/class-bcc-login-visibility.php b/plugins/bcc-login/includes/class-bcc-login-visibility.php index f9001c9..bfda5cf 100644 --- a/plugins/bcc-login/includes/class-bcc-login-visibility.php +++ b/plugins/bcc-login/includes/class-bcc-login-visibility.php @@ -105,14 +105,12 @@ function on_template_redirect() { return; } - $visited_url = add_query_arg( $wp->query_vars, home_url( $wp->request ) ); - $session_is_valid = $this->_client->is_session_valid(); // Initiate new login if session has expired if ( is_user_logged_in() && !$session_is_valid ) { $this->_client->end_login(); - wp_redirect( wp_login_url($visited_url) ); + wp_redirect( wp_login_url(get_page_link()) ); return; } @@ -139,7 +137,7 @@ function on_template_redirect() { if ( is_user_logged_in() ) { return $this->not_allowed_to_view_page(); } else { - wp_redirect( wp_login_url($visited_url) ); + wp_redirect( wp_login_url(get_page_link()) ); } }