Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove added query parameters after login redirect #135

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
30 changes: 6 additions & 24 deletions plugins/bcc-login/includes/class-bcc-login-client.php
Original file line number Diff line number Diff line change
Expand Up @@ -271,41 +271,23 @@ private function get_full_redirect_url() {
private function get_current_url() {
global $wp;
if(isset($_GET['redirect_to'])) {
if( $this->parse_url_origin($_GET['redirect_to']) !== $this->parse_url_origin(site_url()) ) {
if( $this->parse_url_host($_GET['redirect_to']) !== $this->parse_url_host(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 '//' . $_SERVER['HTTP_HOST'] . str_replace('wp-login.php', '', $_SERVER['REQUEST_URI']);
}

private function parse_url_origin($url) {
$origin = "";

private function parse_url_host($url) {
$parsed = parse_url($url);

if ($parsed === false) {
return $origin;
if ($parsed === false || !isset($parsed['host'])) {
return "";
}
if(isset($parsed['scheme']))
$origin .= $parsed['scheme'] . "://";

if(isset($parsed['host']))
$origin .= $parsed['host'];

if(isset($parsed['port']))
$origin .= ":" . $parsed['port'];

return $origin;
return $parsed['host'];
}

private function get_authorization_url( Auth_State $state ) {
Expand Down
2 changes: 1 addition & 1 deletion plugins/bcc-login/includes/class-bcc-login-visibility.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ function on_template_redirect() {
return;
}

$visited_url = add_query_arg( $wp->query_vars, home_url( $wp->request ) );
$visited_url = "//".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];

$session_is_valid = $this->_client->is_session_valid();

Expand Down
Loading