From 3222d87699d993d8b4e866c6ead49f96ba098dec Mon Sep 17 00:00:00 2001 From: =?utf8?q?Tim=20D=C3=BCsterhus?= Date: Sun, 4 May 2014 21:09:51 +0200 Subject: [PATCH] Update GoogleAuth to use the new API --- .../files/lib/action/GoogleAuthAction.class.php | 12 +++++++----- .../install/files/lib/form/RegisterForm.class.php | 14 +++++++++++++- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/wcfsetup/install/files/lib/action/GoogleAuthAction.class.php b/wcfsetup/install/files/lib/action/GoogleAuthAction.class.php index 3cb3fa1093..e5708e3543 100644 --- a/wcfsetup/install/files/lib/action/GoogleAuthAction.class.php +++ b/wcfsetup/install/files/lib/action/GoogleAuthAction.class.php @@ -68,7 +68,7 @@ class GoogleAuthAction extends AbstractAction { try { // fetch userdata - $request = new HTTPRequest('https://www.googleapis.com/oauth2/v1/userinfo'); + $request = new HTTPRequest('https://www.googleapis.com/plus/v1/people/me'); $request->addHeader('Authorization', 'Bearer '.$data['access_token']); $request->execute(); $reply = $request->getReply(); @@ -114,15 +114,17 @@ class GoogleAuthAction extends AbstractAction { // save data for connection if (WCF::getUser()->userID) { - WCF::getSession()->register('__googleUsername', $userData['name']); + WCF::getSession()->register('__googleUsername', $userData['displayName']); WCF::getSession()->register('__googleData', $userData); HeaderUtil::redirect(LinkHandler::getInstance()->getLink('AccountManagement').'#3rdParty'); } // save data and redirect to registration else { - WCF::getSession()->register('__username', $userData['name']); - if (isset($userData['email'])) WCF::getSession()->register('__email', $userData['email']); + WCF::getSession()->register('__username', $userData['displayName']); + if (isset($userData['emails'][0]['value'])) { + WCF::getSession()->register('__email', $userData['emails'][0]['value']); + } WCF::getSession()->register('__googleData', $userData); @@ -145,7 +147,7 @@ class GoogleAuthAction extends AbstractAction { // start auth by redirecting to google $token = StringUtil::getRandomID(); WCF::getSession()->register('__googleInit', $token); - HeaderUtil::redirect("https://accounts.google.com/o/oauth2/auth?client_id=".rawurlencode(StringUtil::trim(GOOGLE_PUBLIC_KEY)). "&redirect_uri=".rawurlencode($callbackURL)."&state=".$token."&scope=https://www.googleapis.com/auth/userinfo.profile+https://www.googleapis.com/auth/userinfo.email&response_type=code"); + HeaderUtil::redirect("https://accounts.google.com/o/oauth2/auth?client_id=".rawurlencode(StringUtil::trim(GOOGLE_PUBLIC_KEY)). "&redirect_uri=".rawurlencode($callbackURL)."&state=".$token."&scope=profile+email&response_type=code"); $this->executed(); exit; } diff --git a/wcfsetup/install/files/lib/form/RegisterForm.class.php b/wcfsetup/install/files/lib/form/RegisterForm.class.php index 925b1f1a52..81f9c98dd1 100644 --- a/wcfsetup/install/files/lib/form/RegisterForm.class.php +++ b/wcfsetup/install/files/lib/form/RegisterForm.class.php @@ -370,7 +370,7 @@ class RegisterForm extends UserAddForm { WCF::getSession()->unregister('__googleData'); - if (isset($googleData['email']) && $googleData['email'] == $this->email) { + if (isset($googleData['emails'][0]['value']) && $googleData['emails'][0]['value'] == $this->email) { $registerVia3rdParty = true; } @@ -385,6 +385,18 @@ class RegisterForm extends UserAddForm { } } if (isset($googleData['birthday'])) $saveOptions[User::getUserOptionID('birthday')] = $googleData['birthday']; + if (isset($googleData['placesLived'])) { + // save primary location + $saveOptions[User::getUserOptionID('location')] = current(array_map( + function ($element) { return $element['value']; }, + array_filter($googleData['placesLived'], function ($element) { return isset($element['primary']) && $element['primary']; }) + )); + } + + // avatar + if (isset($googleData['image']['url'])) { + $avatarURL = $googleData['image']['url']; + } } break; } -- 2.20.1