/users/modules/google_oauth/index.php
PHP | 91 lines | 63 code | 14 blank | 14 comment | 3 complexity | 9c6369592367723523d01c7ddb400bfd MD5 | raw file
1<?php 2/** 3 * @package StartupAPI 4 * @subpackage Authentication 5 */ 6require_once(dirname(dirname(dirname(__FILE__))).'/OAuthModule.php'); 7 8class GoogleOAuthAuthenticationModule extends OAuthAuthenticationModule 9{ 10 protected $userCredentialsClass = 'GoogleOAuthUserCredentials'; 11 12 /** 13 * Constructor for Google OAuth module 14 * @param string $oAuthConsumerKey OAuth Consumer Key 15 * @param string $oAuthConsumerSecret OAuth Consumer Secret 16 * @param array $GoogleAPIScopes (optional) Array of Google API Scopes 17 * See full list here: http://code.google.com/apis/gdata/faq.html#AuthScopes 18 */ 19 public function __construct($oAuthConsumerKey, $oAuthConsumerSecret, 20 $GoogleAPIScopes = null) 21 { 22 // default scope needed for identity verification 23 // TODO rewrite using hybrid OpenID + OAuth implementation 24 $scopes = array('https://www.google.com/m8/feeds/'); 25 26 if (is_array($GoogleAPIScopes)) { 27 $scopes = array_merge($scopes, $GoogleAPIScopes); 28 } 29 30 parent::__construct( 31 'Google', 32 'https://www.google.com/', 33 $oAuthConsumerKey, 34 $oAuthConsumerSecret, 35 'https://www.google.com/accounts/OAuthGetRequestToken', 36 'https://www.google.com/accounts/OAuthGetAccessToken', 37 'https://www.google.com/accounts/OAuthAuthorizeToken', 38 array('HMAC-SHA1'), 39 implode(' ', $scopes), 40 UserConfig::$USERSROOTURL.'/modules/google_oauth/login-button.png', 41 UserConfig::$USERSROOTURL.'/modules/google_oauth/login-button.png', 42 UserConfig::$USERSROOTURL.'/modules/google_oauth/login-button.png', 43 array( 44 array(3001, "Logged in using Google account", 1), 45 array(3002, "Added Google account", 1), 46 array(3003, "Removed Google account", 0), 47 array(3004, "Registered using Google account", 1), 48 ) 49 ); 50 } 51 52 public function getID() 53 { 54 return "google-oauth"; 55 } 56 57 public function getLegendColor() 58 { 59 return "e51837"; 60 } 61 62 public function getTitle() 63 { 64 return "Google"; 65 } 66 67 public function getIdentity($oauth_user_id) { 68 // get meetup user id 69 $request = new OAuthRequester('https://www.google.com/m8/feeds/groups/default/full', 'GET'); 70 $result = $request->doRequest($oauth_user_id); 71 72 $self_url = null; 73 74 if ($result['code'] == 200) { 75 $raw_xml = $result['body']; 76 $xml = new SimpleXMLElement($raw_xml); 77 78 return array( 79 'id' => (string)$xml->id, 80 'name' => (string)$xml->author->name, 81 'email' => (string)$xml->author->email 82 ); 83 } 84 85 86 return null; 87 } 88} 89 90class GoogleOAuthUserCredentials extends OAuthUserCredentials { 91}