From acb2ccdff61ab9d173d49467267568da7f8aa19e Mon Sep 17 00:00:00 2001 From: German Lena Date: Wed, 27 May 2015 12:46:02 -0300 Subject: [PATCH] fixed errors --- lib/WP_Auth0_UserCreator.php | 3 ++- lib/WP_Auth0_UsersRepo.php | 9 +++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/lib/WP_Auth0_UserCreator.php b/lib/WP_Auth0_UserCreator.php index a86ed46e..c2f1f728 100644 --- a/lib/WP_Auth0_UserCreator.php +++ b/lib/WP_Auth0_UserCreator.php @@ -6,7 +6,7 @@ public function tokenHasRequiredScopes($jwt) { return ( (isset($jwt->email) || isset($jwt->nickname)) - && isset(identities) + && isset($jwt->identities) ); } @@ -57,6 +57,7 @@ public function create($userinfo, $token) { } else { throw new WP_Auth0_RegistrationNotEnabledException(); } + // If we are here we should have a valid $user_id with a new user or an existing one // log him in, and update the auth0_user table self::insertAuth0User($userinfo, $user_id); diff --git a/lib/WP_Auth0_UsersRepo.php b/lib/WP_Auth0_UsersRepo.php index 4e7db3a0..85425c39 100644 --- a/lib/WP_Auth0_UsersRepo.php +++ b/lib/WP_Auth0_UsersRepo.php @@ -3,12 +3,13 @@ class WP_Auth0_UsersRepo { public static function init() { - if (WP_Auth0_Options::get('jwt_auth_integration')) { - add_filter( 'wp_jwt_auth_get_user', array( __CLASS__, 'getUser' ), 1,2); + if (WP_Auth0_Options::get('jwt_auth_integration') == 1) { + add_filter( 'wp_jwt_auth_get_user', array( __CLASS__, 'getUser' ), 0,2); } } public static function getUser($jwt, $encodedJWT) { + global $wpdb; $sql = 'SELECT u.* @@ -28,8 +29,8 @@ public static function getUser($jwt, $encodedJWT) { $creator = new WP_Auth0_UserCreator(); - if ($creator->tokenHasRequiredScopes($jwt->email)) { - $auth0User = $jwt + if ($creator->tokenHasRequiredScopes($jwt)) { + $auth0User = $jwt; } else { $auth0User = json_decode($response['body']);