From 8be40caa1551b97b2017044f97ffa7255332663f Mon Sep 17 00:00:00 2001 From: German Lena Date: Fri, 22 May 2015 16:59:14 -0300 Subject: [PATCH] partial commit --- lib/WP_Auth0_UserCreator.php | 9 +++++++++ lib/WP_Auth0_UsersRepo.php | 10 ++++++++-- readme.txt | 2 +- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/lib/WP_Auth0_UserCreator.php b/lib/WP_Auth0_UserCreator.php index fd221783..a86ed46e 100644 --- a/lib/WP_Auth0_UserCreator.php +++ b/lib/WP_Auth0_UserCreator.php @@ -2,6 +2,15 @@ class WP_Auth0_UserCreator { + public function tokenHasRequiredScopes($jwt) { + + return ( + (isset($jwt->email) || isset($jwt->nickname)) + && isset(identities) + ); + + } + public function create($userinfo, $token) { // If the user doesn't exist we need to either create a new one, or asign him to an existing one diff --git a/lib/WP_Auth0_UsersRepo.php b/lib/WP_Auth0_UsersRepo.php index 13f9e270..4e7db3a0 100644 --- a/lib/WP_Auth0_UsersRepo.php +++ b/lib/WP_Auth0_UsersRepo.php @@ -26,10 +26,16 @@ public static function getUser($jwt, $encodedJWT) { if ($response['response']['code'] != 200) return null; - $auth0User = json_decode($response['body']); + $creator = new WP_Auth0_UserCreator(); + + if ($creator->tokenHasRequiredScopes($jwt->email)) { + $auth0User = $jwt + } + else { + $auth0User = json_decode($response['body']); + } try { - $creator = new WP_Auth0_UserCreator(); $user_id = $creator->create($auth0User,$encodedJWT); return new WP_User($user_id); diff --git a/readme.txt b/readme.txt index f4dff706..dd86ef74 100644 --- a/readme.txt +++ b/readme.txt @@ -7,7 +7,7 @@ License URI: https://github.com/auth0/wp-auth0/blob/master/LICENSE.md Stable tag: trunk Contributors: hrajchert, rrauch -Single Sign On for Enterprises + Social Login + User/Passwords. For all your WorpdPress instances. Powered by Auth0. +Single Sign On for Enterprises + Social Login + User/Passwords. For all your WordPress instances. Powered by Auth0. == Description ==