OAuthOAuth2ServiceFacebook

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

Defined (1)

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

/lib/PHPoAuthLib/src/OAuth/OAuth2/Service/Facebook.php  
  1. class Facebook extends AbstractService 
  2. /** 
  3. * Facebook www url - used to build dialog urls 
  4. */ 
  5. const WWW_URL = 'https://www.facebook.com/'; 
  6.  
  7. /** 
  8. * Defined scopes 
  9. * If you don't think this is scary you should not be allowed on the web at all 
  10. * @link https://developers.facebook.com/docs/reference/login/ 
  11. * @link https://developers.facebook.com/tools/explorer For a list of permissions use 'Get Access Token' 
  12. */ 
  13. // email scopes 
  14. const SCOPE_EMAIL = 'email'; 
  15. // extended permissions 
  16. const SCOPE_READ_FRIENDLIST = 'read_friendlists'; 
  17. const SCOPE_READ_INSIGHTS = 'read_insights'; 
  18. const SCOPE_READ_MAILBOX = 'read_mailbox'; 
  19. const SCOPE_READ_PAGE_MAILBOXES = 'read_page_mailboxes'; 
  20. const SCOPE_READ_REQUESTS = 'read_requests'; 
  21. const SCOPE_READ_STREAM = 'read_stream'; 
  22. const SCOPE_VIDEO_UPLOAD = 'video_upload'; 
  23. const SCOPE_XMPP_LOGIN = 'xmpp_login'; 
  24. const SCOPE_USER_ONLINE_PRESENCE = 'user_online_presence'; 
  25. const SCOPE_FRIENDS_ONLINE_PRESENCE = 'friends_online_presence'; 
  26. const SCOPE_ADS_MANAGEMENT = 'ads_management'; 
  27. const SCOPE_ADS_READ = 'ads_read'; 
  28. const SCOPE_CREATE_EVENT = 'create_event'; 
  29. const SCOPE_CREATE_NOTE = 'create_note'; 
  30. const SCOPE_EXPORT_STREAM = 'export_stream'; 
  31. const SCOPE_MANAGE_FRIENDLIST = 'manage_friendlists'; 
  32. const SCOPE_MANAGE_NOTIFICATIONS = 'manage_notifications'; 
  33. const SCOPE_PHOTO_UPLOAD = 'photo_upload'; 
  34. const SCOPE_PUBLISH_ACTIONS = 'publish_actions'; 
  35. const SCOPE_PUBLISH_CHECKINS = 'publish_checkins'; 
  36. const SCOPE_PUBLISH_STREAM = 'publish_stream'; 
  37. const SCOPE_RSVP_EVENT = 'rsvp_event'; 
  38. const SCOPE_SHARE_ITEM = 'share_item'; 
  39. const SCOPE_SMS = 'sms'; 
  40. const SCOPE_STATUS_UPDATE = 'status_update'; 
  41. // Extended Profile Properties 
  42. const SCOPE_USER_FRIENDS = 'user_friends'; 
  43. const SCOPE_USER_ABOUT = 'user_about_me'; 
  44. const SCOPE_FRIENDS_ABOUT = 'friends_about_me'; 
  45. const SCOPE_USER_ACTIVITIES = 'user_activities'; 
  46. const SCOPE_FRIENDS_ACTIVITIES = 'friends_activities'; 
  47. const SCOPE_USER_BIRTHDAY = 'user_birthday'; 
  48. const SCOPE_FRIENDS_BIRTHDAY = 'friends_birthday'; 
  49. const SCOPE_USER_CHECKINS = 'user_checkins'; 
  50. const SCOPE_FRIENDS_CHECKINS = 'friends_checkins'; 
  51. const SCOPE_USER_EDUCATION = 'user_education_history'; 
  52. const SCOPE_FRIENDS_EDUCATION = 'friends_education_history'; 
  53. const SCOPE_USER_EVENTS = 'user_events'; 
  54. const SCOPE_FRIENDS_EVENTS = 'friends_events'; 
  55. const SCOPE_USER_GROUPS = 'user_groups'; 
  56. const SCOPE_FRIENDS_GROUPS = 'friends_groups'; 
  57. const SCOPE_USER_HOMETOWN = 'user_hometown'; 
  58. const SCOPE_FRIENDS_HOMETOWN = 'friends_hometown'; 
  59. const SCOPE_USER_INTERESTS = 'user_interests'; 
  60. const SCOPE_FRIEND_INTERESTS = 'friends_interests'; 
  61. const SCOPE_USER_LIKES = 'user_likes'; 
  62. const SCOPE_FRIENDS_LIKES = 'friends_likes'; 
  63. const SCOPE_USER_LOCATION = 'user_location'; 
  64. const SCOPE_FRIENDS_LOCATION = 'friends_location'; 
  65. const SCOPE_USER_NOTES = 'user_notes'; 
  66. const SCOPE_FRIENDS_NOTES = 'friends_notes'; 
  67. const SCOPE_USER_PHOTOS = 'user_photos'; 
  68. const SCOPE_USER_PHOTO_VIDEO_TAGS = 'user_photo_video_tags'; 
  69. const SCOPE_FRIENDS_PHOTOS = 'friends_photos'; 
  70. const SCOPE_FRIENDS_PHOTO_VIDEO_TAGS = 'friends_photo_video_tags'; 
  71. const SCOPE_USER_QUESTIONS = 'user_questions'; 
  72. const SCOPE_FRIENDS_QUESTIONS = 'friends_questions'; 
  73. const SCOPE_USER_RELATIONSHIPS = 'user_relationships'; 
  74. const SCOPE_FRIENDS_RELATIONSHIPS = 'friends_relationships'; 
  75. const SCOPE_USER_RELATIONSHIPS_DETAILS = 'user_relationship_details'; 
  76. const SCOPE_FRIENDS_RELATIONSHIPS_DETAILS = 'friends_relationship_details'; 
  77. const SCOPE_USER_RELIGION = 'user_religion_politics'; 
  78. const SCOPE_FRIENDS_RELIGION = 'friends_religion_politics'; 
  79. const SCOPE_USER_STATUS = 'user_status'; 
  80. const SCOPE_FRIENDS_STATUS = 'friends_status'; 
  81. const SCOPE_USER_SUBSCRIPTIONS = 'user_subscriptions'; 
  82. const SCOPE_FRIENDS_SUBSCRIPTIONS = 'friends_subscriptions'; 
  83. const SCOPE_USER_VIDEOS = 'user_videos'; 
  84. const SCOPE_FRIENDS_VIDEOS = 'friends_videos'; 
  85. const SCOPE_USER_WEBSITE = 'user_website'; 
  86. const SCOPE_FRIENDS_WEBSITE = 'friends_website'; 
  87. const SCOPE_USER_WORK = 'user_work_history'; 
  88. const SCOPE_FRIENDS_WORK = 'friends_work_history'; 
  89. // Open Graph Permissions 
  90. const SCOPE_USER_MUSIC = 'user_actions.music'; 
  91. const SCOPE_FRIENDS_MUSIC = 'friends_actions.music'; 
  92. const SCOPE_USER_NEWS = 'user_actions.news'; 
  93. const SCOPE_FRIENDS_NEWS = 'friends_actions.news'; 
  94. const SCOPE_USER_VIDEO = 'user_actions.video'; 
  95. const SCOPE_FRIENDS_VIDEO = 'friends_actions.video'; 
  96. const SCOPE_USER_APP = 'user_actions:APP_NAMESPACE'; 
  97. const SCOPE_FRIENDS_APP = 'friends_actions:APP_NAMESPACE'; 
  98. const SCOPE_USER_GAMES = 'user_games_activity'; 
  99. const SCOPE_FRIENDS_GAMES = 'friends_games_activity'; 
  100. //Page Permissions 
  101. const SCOPE_PAGES = 'manage_pages'; 
  102.  
  103. public function __construct( 
  104. CredentialsInterface $credentials,  
  105. ClientInterface $httpClient,  
  106. TokenStorageInterface $storage,  
  107. $scopes = array(),  
  108. UriInterface $baseApiUri = null 
  109. ) { 
  110. parent::__construct($credentials, $httpClient, $storage, $scopes, $baseApiUri); 
  111.  
  112. if (null === $baseApiUri) { 
  113. $this->baseApiUri = new Uri('https://graph.facebook.com/'); 
  114.  
  115. /** 
  116. * {@inheritdoc} 
  117. */ 
  118. public function getAuthorizationEndpoint() 
  119. return new Uri('https://www.facebook.com/dialog/oauth'); 
  120.  
  121. /** 
  122. * {@inheritdoc} 
  123. */ 
  124. public function getAccessTokenEndpoint() 
  125. return new Uri('https://graph.facebook.com/oauth/access_token'); 
  126.  
  127. /** 
  128. * {@inheritdoc} 
  129. */ 
  130. protected function parseAccessTokenResponse($responseBody) 
  131. // Facebook gives us a query string ... Oh wait. JSON is too simple, understand ? 
  132. parse_str($responseBody, $data); 
  133.  
  134. if (null === $data || !is_array($data)) { 
  135. throw new TokenResponseException('Unable to parse response.'); 
  136. } elseif (isset($data['error'])) { 
  137. throw new TokenResponseException('Error in retrieving token: "' . $data['error'] . '"'); 
  138.  
  139. $token = new StdOAuth2Token(); 
  140. $token->setAccessToken($data['access_token']); 
  141.  
  142. if (isset($data['expires'])) { 
  143. $token->setLifeTime($data['expires']); 
  144.  
  145. if (isset($data['refresh_token'])) { 
  146. $token->setRefreshToken($data['refresh_token']); 
  147. unset($data['refresh_token']); 
  148.  
  149. unset($data['access_token']); 
  150. unset($data['expires']); 
  151.  
  152. $token->setExtraParams($data); 
  153.  
  154. return $token; 
  155.  
  156. public function getDialogUri($dialogPath, array $parameters) 
  157. if (!isset($parameters['redirect_uri'])) { 
  158. throw new Exception("Redirect uri is mandatory for this request"); 
  159. $parameters['app_id'] = $this->credentials->getConsumerId(); 
  160. $baseUrl = self::WWW_URL . 'dialog/' . $dialogPath; 
  161. $query = http_build_query($parameters); 
  162. return new Uri($baseUrl . '?' . $query);