OAuthOAuth2ServiceGoogle

The Gravity Forms Salesforce Add-On OAuth OAuth2 Service Google class.

Defined (1)

The class is defined in the following location(s).

/lib/PHPoAuthLib/src/OAuth/OAuth2/Service/Google.php  
  1. class Google extends AbstractService 
  2. /** 
  3. * Defined scopes - More scopes are listed here: 
  4. * https://developers.google.com/oauthplayground/ 
  5. * Make a pull request if you need more scopes. 
  6. */ 
  7.  
  8. // Basic 
  9. const SCOPE_EMAIL = 'email'; 
  10. const SCOPE_PROFILE = 'profile'; 
  11.  
  12. const SCOPE_USERINFO_EMAIL = 'https://www.googleapis.com/auth/userinfo.email'; 
  13. const SCOPE_USERINFO_PROFILE = 'https://www.googleapis.com/auth/userinfo.profile'; 
  14.  
  15. // Google+ 
  16. const SCOPE_GPLUS_ME = 'https://www.googleapis.com/auth/plus.me'; 
  17. const SCOPE_GPLUS_LOGIN = 'https://www.googleapis.com/auth/plus.login'; 
  18.  
  19. // Google Drive 
  20. const SCOPE_DOCUMENTSLIST = 'https://docs.google.com/feeds/'; 
  21. const SCOPE_SPREADSHEETS = 'https://spreadsheets.google.com/feeds/'; 
  22. const SCOPE_GOOGLEDRIVE = 'https://www.googleapis.com/auth/drive'; 
  23. const SCOPE_DRIVE_APPS = 'https://www.googleapis.com/auth/drive.appdata'; 
  24. const SCOPE_DRIVE_APPS_READ_ONLY = 'https://www.googleapis.com/auth/drive.apps.readonly'; 
  25. const SCOPE_GOOGLEDRIVE_FILES = 'https://www.googleapis.com/auth/drive.file'; 
  26. const SCOPE_DRIVE_METADATA_READ_ONLY = 'https://www.googleapis.com/auth/drive.metadata.readonly'; 
  27. const SCOPE_DRIVE_READ_ONLY = 'https://www.googleapis.com/auth/drive.readonly'; 
  28. const SCOPE_DRIVE_SCRIPTS = 'https://www.googleapis.com/auth/drive.scripts'; 
  29.  
  30. // Adwords 
  31. const SCOPE_ADSENSE = 'https://www.googleapis.com/auth/adsense'; 
  32. const SCOPE_ADWORDS = 'https://adwords.google.com/api/adwords/'; 
  33. const SCOPE_GAN = 'https://www.googleapis.com/auth/gan'; // google affiliate network...? 
  34.  
  35. // Google Analytics 
  36. const SCOPE_ANALYTICS = 'https://www.googleapis.com/auth/analytics'; 
  37. const SCOPE_ANALYTICS_EDIT = 'https://www.googleapis.com/auth/analytics.edit'; 
  38. const SCOPE_ANALYTICS_MANAGE_USERS = 'https://www.googleapis.com/auth/analytics.manage.users'; 
  39. const SCOPE_ANALYTICS_READ_ONLY = 'https://www.googleapis.com/auth/analytics.readonly'; 
  40.  
  41. // Other services 
  42. const SCOPE_BOOKS = 'https://www.googleapis.com/auth/books'; 
  43. const SCOPE_BLOGGER = 'https://www.googleapis.com/auth/blogger'; 
  44. const SCOPE_CALENDAR = 'https://www.googleapis.com/auth/calendar'; 
  45. const SCOPE_CALENDAR_READ_ONLY = 'https://www.googleapis.com/auth/calendar.readonly'; 
  46. const SCOPE_CONTACT = 'https://www.google.com/m8/feeds/'; 
  47. const SCOPE_CHROMEWEBSTORE = 'https://www.googleapis.com/auth/chromewebstore.readonly'; 
  48. const SCOPE_GMAIL = 'https://mail.google.com/mail/feed/atom'; 
  49. const SCOPE_PICASAWEB = 'https://picasaweb.google.com/data/'; 
  50. const SCOPE_SITES = 'https://sites.google.com/feeds/'; 
  51. const SCOPE_URLSHORTENER = 'https://www.googleapis.com/auth/urlshortener'; 
  52. const SCOPE_WEBMASTERTOOLS = 'https://www.google.com/webmasters/tools/feeds/'; 
  53. const SCOPE_TASKS = 'https://www.googleapis.com/auth/tasks'; 
  54.  
  55. // Cloud services 
  56. const SCOPE_CLOUDSTORAGE = 'https://www.googleapis.com/auth/devstorage.read_write'; 
  57. const SCOPE_CONTENTFORSHOPPING = 'https://www.googleapis.com/auth/structuredcontent'; // what even is this 
  58. const SCOPE_USER_PROVISIONING = 'https://apps-apis.google.com/a/feeds/user/'; 
  59. const SCOPE_GROUPS_PROVISIONING = 'https://apps-apis.google.com/a/feeds/groups/'; 
  60. const SCOPE_NICKNAME_PROVISIONING = 'https://apps-apis.google.com/a/feeds/alias/'; 
  61.  
  62. // Old 
  63. const SCOPE_ORKUT = 'https://www.googleapis.com/auth/orkut'; 
  64. const SCOPE_GOOGLELATITUDE = 
  65. 'https://www.googleapis.com/auth/latitude.all.best https://www.googleapis.com/auth/latitude.all.city'; 
  66. const SCOPE_OPENID = 'openid'; 
  67.  
  68. // YouTube 
  69. const SCOPE_YOUTUBE_GDATA = 'https://gdata.youtube.com'; 
  70. const SCOPE_YOUTUBE_ANALYTICS_MONETARY = 'https://www.googleapis.com/auth/yt-analytics-monetary.readonly'; 
  71. const SCOPE_YOUTUBE_ANALYTICS = 'https://www.googleapis.com/auth/yt-analytics.readonly'; 
  72. const SCOPE_YOUTUBE = 'https://www.googleapis.com/auth/youtube'; 
  73. const SCOPE_YOUTUBE_READ_ONLY = 'https://www.googleapis.com/auth/youtube.readonly'; 
  74. const SCOPE_YOUTUBE_UPLOAD = 'https://www.googleapis.com/auth/youtube.upload'; 
  75. const SCOPE_YOUTUBE_PATNER = 'https://www.googleapis.com/auth/youtubepartner'; 
  76. const SCOPE_YOUTUBE_PARTNER_EDIT = 'https://www.googleapis.com/auth/youtubepartner-channel-edit'; 
  77.  
  78. // Google Glass 
  79. const SCOPE_GLASS_TIMELINE = 'https://www.googleapis.com/auth/glass.timeline'; 
  80. const SCOPE_GLASS_LOCATION = 'https://www.googleapis.com/auth/glass.location'; 
  81.  
  82. // Android Publisher 
  83. const SCOPE_ANDROID_PUBLISHER = 'https://www.googleapis.com/auth/androidpublisher'; 
  84.  
  85. protected $accessType = 'online'; 
  86.  
  87.  
  88. public function setAccessType($accessType) 
  89. if (!in_array($accessType, array('online', 'offline'), true)) { 
  90. throw new InvalidAccessTypeException('Invalid accessType, expected either online or offline'); 
  91. $this->accessType = $accessType; 
  92.  
  93. /** 
  94. * {@inheritdoc} 
  95. */ 
  96. public function getAuthorizationEndpoint() 
  97. return new Uri('https://accounts.google.com/o/oauth2/auth?access_type=' . $this->accessType); 
  98.  
  99. /** 
  100. * {@inheritdoc} 
  101. */ 
  102. public function getAccessTokenEndpoint() 
  103. return new Uri('https://accounts.google.com/o/oauth2/token'); 
  104.  
  105. /** 
  106. * {@inheritdoc} 
  107. */ 
  108. protected function parseAccessTokenResponse($responseBody) 
  109. $data = json_decode($responseBody, true); 
  110.  
  111. if (null === $data || !is_array($data)) { 
  112. throw new TokenResponseException('Unable to parse response.'); 
  113. } elseif (isset($data['error'])) { 
  114. throw new TokenResponseException('Error in retrieving token: "' . $data['error'] . '"'); 
  115.  
  116. $token = new StdOAuth2Token(); 
  117. $token->setAccessToken($data['access_token']); 
  118. $token->setLifetime($data['expires_in']); 
  119.  
  120. if (isset($data['refresh_token'])) { 
  121. $token->setRefreshToken($data['refresh_token']); 
  122. unset($data['refresh_token']); 
  123.  
  124. unset($data['access_token']); 
  125. unset($data['expires_in']); 
  126.  
  127. $token->setExtraParams($data); 
  128.  
  129. return $token;