summaryrefslogtreecommitdiff
path: root/app/Auth
diff options
context:
space:
mode:
authorFrederic Guillot <fred@kanboard.net>2015-07-16 07:28:46 -0400
committerFrederic Guillot <fred@kanboard.net>2015-07-16 07:28:46 -0400
commit12036aa21f4308aca4d816864b357f9627a0f437 (patch)
treeb333a38750e06430c667c49d259155d492fbf087 /app/Auth
parent0bbc6da50ae8b23a8cc6c1217dcd345c0ddb5b7a (diff)
Refactoring of Google Authentication (new callback url)
Diffstat (limited to 'app/Auth')
-rw-r--r--app/Auth/Google.php78
1 files changed, 29 insertions, 49 deletions
diff --git a/app/Auth/Google.php b/app/Auth/Google.php
index 9a977037..dd8f3834 100644
--- a/app/Auth/Google.php
+++ b/app/Auth/Google.php
@@ -3,11 +3,6 @@
namespace Auth;
use Event\AuthEvent;
-use OAuth\Common\Storage\Session;
-use OAuth\Common\Consumer\Credentials;
-use OAuth\Common\Http\Uri\UriFactory;
-use OAuth\ServiceFactory;
-use OAuth\Common\Http\Exception\TokenResponseException;
/**
* Google backend
@@ -25,6 +20,13 @@ class Google extends Base
const AUTH_NAME = 'Google';
/**
+ * OAuth2 instance
+ *
+ * @var \Core\OAuth2
+ */
+ private $service;
+
+ /**
* Authenticate a Google user
*
* @access public
@@ -78,63 +80,41 @@ class Google extends Base
}
/**
- * Get the Google service instance
+ * Get OAuth2 configured service
*
* @access public
- * @return \OAuth\OAuth2\Service\Google
+ * @return \Core\OAuth2
*/
public function getService()
{
- $uriFactory = new UriFactory();
- $currentUri = $uriFactory->createFromSuperGlobalArray($_SERVER);
- $currentUri->setQuery('controller=user&action=google');
-
- $storage = new Session(false);
-
- $credentials = new Credentials(
- GOOGLE_CLIENT_ID,
- GOOGLE_CLIENT_SECRET,
- $currentUri->getAbsoluteUri()
- );
-
- $serviceFactory = new ServiceFactory();
-
- return $serviceFactory->createService(
- 'google',
- $credentials,
- $storage,
- array('userinfo_email', 'userinfo_profile')
- );
- }
+ if (empty($this->service)) {
+ $this->service = $this->oauth->createService(
+ GOOGLE_CLIENT_ID,
+ GOOGLE_CLIENT_SECRET,
+ $this->helper->url->to('oauth', 'google', array(), '', true),
+ 'https://accounts.google.com/o/oauth2/auth',
+ 'https://accounts.google.com/o/oauth2/token',
+ array('https://www.googleapis.com/auth/userinfo.email', 'https://www.googleapis.com/auth/userinfo.profile')
+ );
+ }
- /**
- * Get the authorization URL
- *
- * @access public
- * @return \OAuth\Common\Http\Uri\Uri
- */
- public function getAuthorizationUrl()
- {
- return $this->getService()->getAuthorizationUri();
+ return $this->service;
}
/**
- * Get Google profile information from the API
+ * Get Google profile
*
* @access public
- * @param string $code Google authorization code
- * @return bool|array
+ * @param string $code
+ * @return array
*/
- public function getGoogleProfile($code)
+ public function getProfile($code)
{
- try {
+ $this->getService()->getAccessToken($code);
- $googleService = $this->getService();
- $googleService->requestAccessToken($code);
- return json_decode($googleService->request('https://www.googleapis.com/oauth2/v1/userinfo'), true);
- }
- catch (TokenResponseException $e) {
- return false;
- }
+ return $this->httpClient->getJson(
+ 'https://www.googleapis.com/oauth2/v1/userinfo',
+ array($this->getService()->getAuthorizationHeader()
+ ));
}
}