Last active
August 1, 2018 11:39
-
-
Save sumitpore/2ac3586580ade6c6fe52a400e8aaf6d2 to your computer and use it in GitHub Desktop.
'OAuth Client (Single Sign On)' WordPress Plugin Patch which diplays error on Login Page occurred During oAuth Authorization.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff -Naurw single-sign-on-client/includes/callback.php single-sign-on-client-modified/includes/callback.php | |
--- single-sign-on-client/includes/callback.php 2018-04-12 13:54:50.000000000 +0530 | |
+++ single-sign-on-client-modified/includes/callback.php 2018-08-01 16:32:47.515616000 +0530 | |
@@ -18,6 +18,23 @@ | |
$options = get_option( 'wposso_options' ); | |
$user_redirect = wpssoc_get_user_redirect_url(); | |
+// If error is present in the url, pass that error to login page | |
+$error_code = isset( $_REQUEST['error'] ) ? $_REQUEST['error'] : ''; | |
+$error_description = isset( $_REQUEST['error_description'] ) ? $_REQUEST['error_description'] : __( 'Error occurred during login. Error Code: ' ) . strtoupper( $error_code ); | |
+ | |
+if ( ! empty( trim( $error_code ) ) ) { | |
+ wp_redirect( | |
+ add_query_arg( | |
+ array( | |
+ 'oauth_login_error_code' => urlencode( $error_code ), | |
+ 'oauth_login_error_description' => urlencode( $error_description ), | |
+ ), | |
+ wp_login_url() | |
+ ) | |
+ ); | |
+ exit; | |
+} | |
+ | |
// Authenticate Check and Redirect | |
if ( ! isset( $_GET['code'] ) ) { | |
$params = array( | |
@@ -25,7 +42,7 @@ | |
'response_type' => 'code', | |
'client_id' => $options['client_id'], | |
'client_secret' => $options['client_secret'], | |
- 'redirect_uri' => site_url( '?auth=sso' ) | |
+ 'redirect_uri' => site_url( '?auth=sso' ), | |
); | |
$params = http_build_query( $params ); | |
wp_redirect( $options['server_url'] . '?' . $params ); | |
@@ -37,7 +54,8 @@ | |
$code = sanitize_text_field( $_GET['code'] ); | |
$server_url = $options['server_url'] . '?oauth=token'; | |
- $response = wp_remote_post( $server_url, array( | |
+ $response = wp_remote_post( | |
+ $server_url, array( | |
'method' => 'POST', | |
'timeout' => 45, | |
'redirection' => 5, | |
@@ -49,11 +67,12 @@ | |
'code' => $code, | |
'client_id' => $options['client_id'], | |
'client_secret' => $options['client_secret'], | |
- 'redirect_uri' => site_url( '?auth=sso' ) | |
+ 'redirect_uri' => site_url( '?auth=sso' ), | |
), | |
'cookies' => array(), | |
- 'sslverify' => false | |
- ) ); | |
+ 'sslverify' => false, | |
+ ) | |
+ ); | |
$tokens = json_decode( $response['body'] ); | |
@@ -62,14 +81,16 @@ | |
} | |
$server_url = $options['server_url'] . '?oauth=me&access_token=' . $tokens->access_token; | |
- $response = wp_remote_get( $server_url, array( | |
+ $response = wp_remote_get( | |
+ $server_url, array( | |
'timeout' => 45, | |
'redirection' => 5, | |
'httpversion' => '1.0', | |
'blocking' => true, | |
'headers' => array(), | |
- 'sslverify' => false | |
- ) ); | |
+ 'sslverify' => false, | |
+ ) | |
+ ); | |
$user_info = json_decode( $response['body'] ); | |
$user_id = username_exists( $user_info->user_login ); | |
@@ -91,7 +112,6 @@ | |
wp_redirect( $user_redirect ); | |
exit; | |
} | |
- | |
} else { | |
// Already Registered... Log the User In | |
@@ -116,7 +136,6 @@ | |
wp_redirect( $user_redirect ); | |
exit; | |
} | |
- | |
} | |
exit( 'Single Sign On Failed.' ); | |
diff -Naurw single-sign-on-client/includes/filters.php single-sign-on-client-modified/includes/filters.php | |
--- single-sign-on-client/includes/filters.php 2016-09-12 13:54:10.000000000 +0530 | |
+++ single-sign-on-client-modified/includes/filters.php 2018-08-01 16:04:21.088907000 +0530 | |
@@ -4,3 +4,4 @@ | |
*/ | |
defined( 'ABSPATH' ) or die( 'No script kiddies please!' ); | |
\ No newline at end of file | |
+ | |
diff -Naurw single-sign-on-client/includes/functions.php single-sign-on-client-modified/includes/functions.php | |
--- single-sign-on-client/includes/functions.php 2018-04-12 13:54:50.000000000 +0530 | |
+++ single-sign-on-client-modified/includes/functions.php 2018-08-01 16:38:06.894949000 +0530 | |
@@ -34,13 +34,15 @@ | |
* @return [type] [description] | |
*/ | |
function single_sign_on_login_button_shortcode( $atts ) { | |
- $a = shortcode_atts( array( | |
+ $a = shortcode_atts( | |
+ array( | |
'type' => 'primary', | |
'title' => 'Login using Single Sign On', | |
'class' => 'sso-button', | |
'target' => '_blank', | |
- 'text' => 'Single Sign On' | |
- ), $atts ); | |
+ 'text' => 'Single Sign On', | |
+ ), $atts | |
+ ); | |
return '<a class="' . $a['class'] . '" href="' . site_url( '?auth=sso' ) . '" title="' . $a['title'] . '" target="' . $a['target'] . '">' . $a['text'] . '</a>'; | |
} | |
@@ -57,3 +59,16 @@ | |
return $user_redirect; | |
} | |
\ No newline at end of file | |
+ | |
+ | |
+/** | |
+ * Display Error Message on Login page occurred during oAuth Authorization | |
+ */ | |
+function wp_sso_login_errors( $errors ) { | |
+ | |
+ if ( isset( $_GET['oauth_login_error_code'] ) && ! empty( $_GET['oauth_login_error_code'] ) ) { | |
+ $errors->add( urldecode( $_GET['oauth_login_error_code'] ), '<strong>' . $_GET['oauth_login_error_description'] . '</strong>', 'error' ); | |
+ } | |
+ return $errors; | |
+} | |
+add_filter( 'wp_login_errors', 'wp_sso_login_errors', 10, 1 ); | |
diff -Naurw single-sign-on-client/library/class-wposso-client.php single-sign-on-client-modified/library/class-wposso-client.php | |
--- single-sign-on-client/library/class-wposso-client.php 2018-04-12 13:54:50.000000000 +0530 | |
+++ single-sign-on-client-modified/library/class-wposso-client.php 2018-08-01 16:11:36.180501000 +0530 | |
@@ -17,7 +17,7 @@ | |
public static $_instance = null; | |
/** Default Settings */ | |
- protected $defualt_settings = array( | |
+ protected $default_settings = array( | |
'client_id' => '', | |
'client_secret' => '', | |
'server_url' => '', | |
@@ -62,7 +62,7 @@ | |
$options = get_option( "wposso_options" ); | |
if ( ! isset( $options["server_url"] ) ) { | |
- update_option( "wposso_options", $this->defualt_settings ); | |
+ update_option( "wposso_options", $this->default_settings ); | |
} | |
$this->install(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment