diff --git a/includes/openid-connect-generic-client-wrapper.php b/includes/openid-connect-generic-client-wrapper.php
index fed9858..37b43aa 100644
--- a/includes/openid-connect-generic-client-wrapper.php
+++ b/includes/openid-connect-generic-client-wrapper.php
@@ -12,7 +12,10 @@ class OpenID_Connect_Generic_Client_Wrapper {
// internal tracking cookie key
private $cookie_id_key = 'openid-connect-generic-identity';
-
+
+ // user redirect cookie key
+ public $cookie_redirect_key = 'openid-connect-generic-redirect';
+
// WP_Error if there was a problem, or false if no error
private $error = false;
@@ -258,8 +261,15 @@ class OpenID_Connect_Generic_Client_Wrapper {
// log our success
$this->logger->log( "Successful login for: {$user->user_login} ({$user->ID})", 'login-success' );
- // go home!
- wp_redirect( home_url() );
+ // redirect back to the origin page if enabled
+ if( $this->settings->redirect_user_back && !empty( $redirect_url = esc_url( $_COOKIE[ $this->cookie_redirect_key ] ) ) ) {
+ do_action( 'openid-connect-generic-redirect-user-back', $redirect_url, $user );
+ wp_redirect( $redirect_url );
+ }
+ // otherwise, go home!
+ else {
+ wp_redirect( home_url() );
+ }
}
/**
diff --git a/includes/openid-connect-generic-login-form.php b/includes/openid-connect-generic-login-form.php
index 3760017..1e587dd 100644
--- a/includes/openid-connect-generic-login-form.php
+++ b/includes/openid-connect-generic-login-form.php
@@ -26,6 +26,9 @@ class OpenID_Connect_Generic_Login_Form {
// alter the login form as dictated by settings
add_filter( 'login_message', array( $login_form, 'handle_login_page' ), 99 );
+ // add a shortcode for the login button
+ add_shortcode( 'openid_connect_generic_login_button', array( $login_form, 'make_login_button' ) );
+
return $login_form;
}
@@ -83,6 +86,20 @@ class OpenID_Connect_Generic_Login_Form {
$text = apply_filters( 'openid-connect-generic-login-button-text', __( 'Login with OpenID Connect' ) );
$href = $this->client_wrapper->get_authentication_url();
+ // record the URL of this page if set to redirect back to origin page
+ if( $this->settings->redirect_user_back ) {
+ $redirect_expiry = time() + DAY_IN_SECONDS;
+ if ( $GLOBALS['pagenow'] == 'wp-login.php' ) {
+ if( isset( $_REQUEST['redirect_to'] ) )
+ $redirect_url = esc_url( $_REQUEST['redirect_to'] );
+ else
+ $redirect_url = admin_url();
+ } else {
+ $redirect_url = home_url( esc_url( add_query_arg( NULL, NULL ) ) );
+ }
+ setcookie( $this->client_wrapper->cookie_redirect_key, $redirect_url, $redirect_expiry, COOKIEPATH, COOKIE_DOMAIN, is_ssl() );
+ }
+
ob_start();
?>
diff --git a/includes/openid-connect-generic-settings-page.php b/includes/openid-connect-generic-settings-page.php
index a05588e..5859071 100644
--- a/includes/openid-connect-generic-settings-page.php
+++ b/includes/openid-connect-generic-settings-page.php
@@ -117,6 +117,12 @@ class OpenID_Connect_Generic_Settings_Page {
'type' => 'checkbox',
'section' => 'user_settings',
),
+ 'redirect_user_back' => array(
+ 'title' => __( 'Redirect Back to Origin Page' ),
+ 'description' => __( 'After a successful OpenID Connect authentication, this will override the default action of redirecting the user to the home page and instead redirect the user back to the page on which they clicked the OpenID Connect login button. This will cause the login process to proceed in a traditional WordPress fashion. For example, users logging in through the default wp-login.php page would end up on the WordPress Dashboard and users logging in through the WooCommerce "My Account" page would end up on their account page.' ),
+ 'type' => 'checkbox',
+ 'section' => 'user_settings',
+ ),
'enable_logging' => array(
'title' => __( 'Enable Logging' ),
'description' => __( 'Very simple log messages for debugging purposes.' ),
diff --git a/openid-connect-generic.php b/openid-connect-generic.php
index 01fe328..80c13cc 100644
--- a/openid-connect-generic.php
+++ b/openid-connect-generic.php
@@ -3,7 +3,7 @@
Plugin Name: OpenID Connect - Generic Client
Plugin URI: https://github.com/daggerhart/openid-connect-generic
Description: Connect to an OpenID Connect identity provider with Authorization Code Flow
-Version: 3.0.3
+Version: 3.0.5
Author: daggerhart
Author URI: http://www.daggerhart.com
License: GPLv2 Copyright (c) 2015 daggerhart
diff --git a/readme.md b/readme.md
index 89c81eb..5911ffe 100644
--- a/readme.md
+++ b/readme.md
@@ -34,6 +34,15 @@ Replace `example.com` with your domain name and path to WordPress.
### Changelog
+**3.0.5**
+
+* Added [openid_connect_generic_login_button] shortcode to allow the login button to be placed anywhere
+* Added setting to "Redirect Back to Origin Page" after a successful login instead of redirecting to the home page.
+
+**3.0.4**
+
+* Added setting to allow linking existing WordPress user accounts with newly-authenticated OpenID Connect login
+
**3.0.3**
* Using WordPresss's is_ssl() for setcookie()'s "secure" parameter
diff --git a/readme.txt b/readme.txt
index 5d648bc..fcf3930 100644
--- a/readme.txt
+++ b/readme.txt
@@ -40,6 +40,15 @@ Replace `example.com` with your domain name and path to WordPress.
== Changelog ==
+= 3.0.5 =
+
+* Added [openid_connect_generic_login_button] shortcode to allow the login button to be placed anywhere
+* Added setting to "Redirect Back to Origin Page" after a successful login instead of redirecting to the home page.
+
+= 3.0.4 =
+
+* Added setting to allow linking existing WordPress user accounts with newly-authenticated OpenID Connect login
+
= 3.0.3 =
* Using WordPresss's is_ssl() for setcookie()'s "secure" parameter