Skip to content

Commit

Permalink
Merge pull request #192 from pantheon-systems/191-allow-redirect-wp-l…
Browse files Browse the repository at this point in the history
…ogin

Allow redirecting back to `wp-login.php` while avoiding redirect loop
  • Loading branch information
danielbachhuber authored May 26, 2020
2 parents f4d8c7b + 712c205 commit bd06228
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 58 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,9 @@ There is no third step. Because SimpleSAMLphp loads WordPress, which has WP Nati

## Changelog ##

### 1.0.1 (May 26, 2020) ###
* Allows redirecting back to `wp-login.php` while avoiding redirect loop [[#192](https://github.com/pantheon-systems/wp-saml-auth/pull/192)].

### 1.0.0 (March 2, 2020) ###
* Plugin is stable.

Expand Down
83 changes: 42 additions & 41 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 17 additions & 10 deletions inc/class-wp-saml-auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -243,16 +243,23 @@ public function do_saml_authentication() {
// Translators: Includes error reason from OneLogin.
return new WP_Error( 'wp_saml_auth_unauthenticated', sprintf( __( 'User is not authenticated with SAML IdP. Reason: %s', 'wp-saml-auth' ), $this->provider->getLastErrorReason() ) );
}
$attributes = $this->provider->getAttributes();
$redirect_to = filter_input( INPUT_POST, 'RelayState', FILTER_SANITIZE_URL );
if ( $redirect_to && false === stripos( $redirect_to, parse_url( wp_login_url(), PHP_URL_PATH ) ) ) {
add_filter(
'login_redirect',
function() use ( $redirect_to ) {
return $redirect_to;
},
1
);
$attributes = $this->provider->getAttributes();
$redirect_to = filter_input( INPUT_POST, 'RelayState', FILTER_SANITIZE_URL );
$permit_wp_login = self::get_option( 'permit_wp_login' );
if ( $redirect_to ) {
// When $permit_wp_login=true, we only care about accidentially triggering the redirect
// to the IDP. However, when $permit_wp_login=false, hitting wp-login will always
// trigger the IDP redirect.
if ( ( $permit_wp_login && false === stripos( $redirect_to, 'action=wp-saml-auth' ) )
|| ( ! $permit_wp_login && false === stripos( $redirect_to, parse_url( wp_login_url(), PHP_URL_PATH ) ) ) ) {
add_filter(
'login_redirect',
function() use ( $redirect_to ) {
return $redirect_to;
},
1
);
}
}
} else {
$redirect_to = filter_input( INPUT_GET, 'redirect_to', FILTER_SANITIZE_URL );
Expand Down
12 changes: 6 additions & 6 deletions languages/wp-saml-auth.pot
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
# This file is distributed under the same license as the WP SAML Auth plugin.
msgid ""
msgstr ""
"Project-Id-Version: WP SAML Auth 0.8.3\n"
"Project-Id-Version: WP SAML Auth 1.0.1\n"
"Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/wp-saml-auth\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <[email protected]>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"POT-Creation-Date: 2020-02-03T23:02:50+00:00\n"
"POT-Creation-Date: 2020-05-26T12:03:20+00:00\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"X-Generator: WP-CLI 2.4.0\n"
"X-Domain: wp-saml-auth\n"
Expand Down Expand Up @@ -209,19 +209,19 @@ msgstr ""
msgid "User is not authenticated with SAML IdP. Reason: %s"
msgstr ""

#: inc/class-wp-saml-auth.php:290
#: inc/class-wp-saml-auth.php:297
msgid "Invalid provider specified for SAML authentication"
msgstr ""

#: inc/class-wp-saml-auth.php:315
#: inc/class-wp-saml-auth.php:322
msgid "No attributes were present in SAML response. Attributes are used to create and fetch users. Please contact your administrator"
msgstr ""

#. Translators: Communicates how the user is fetched based on the SAML response.
#: inc/class-wp-saml-auth.php:322
#: inc/class-wp-saml-auth.php:329
msgid "\"%1$s\" attribute is expected, but missing, in SAML response. Attribute is used to fetch existing user by \"%2$s\". Please contact your administrator."
msgstr ""

#: inc/class-wp-saml-auth.php:337
#: inc/class-wp-saml-auth.php:344
msgid "No WordPress user exists for your account. Please contact your administrator."
msgstr ""
3 changes: 3 additions & 0 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,9 @@ There is no third step. Because SimpleSAMLphp loads WordPress, which has WP Nati

== Changelog ==

= 1.0.1 (May 26, 2020) =
* Allows redirecting back to `wp-login.php` while avoiding redirect loop [[#192](https://github.com/pantheon-systems/wp-saml-auth/pull/192)].

= 1.0.0 (March 2, 2020) =
* Plugin is stable.

Expand Down
2 changes: 1 addition & 1 deletion wp-saml-auth.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
/**
* Plugin Name: WP SAML Auth
* Version: 1.0.0
* Version: 1.0.1
* Description: SAML authentication for WordPress, using SimpleSAMLphp.
* Author: Pantheon
* Author URI: https://pantheon.io
Expand Down

0 comments on commit bd06228

Please sign in to comment.