PageRenderTime 35ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/users/modules/google_oauth/index.php

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