OAuthOAuth1ServiceTwitter

The Gravity Forms Salesforce Add-On OAuth OAuth1 Service Twitter class.

Defined (1)

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

/lib/PHPoAuthLib/src/OAuth/OAuth1/Service/Twitter.php  
  1. class Twitter extends AbstractService 
  2. const ENDPOINT_AUTHENTICATE = "https://api.twitter.com/oauth/authenticate"; 
  3. const ENDPOINT_AUTHORIZE = "https://api.twitter.com/oauth/authorize"; 
  4.  
  5. protected $authorizationEndpoint = self::ENDPOINT_AUTHENTICATE; 
  6.  
  7. public function __construct( 
  8. CredentialsInterface $credentials,  
  9. ClientInterface $httpClient,  
  10. TokenStorageInterface $storage,  
  11. SignatureInterface $signature,  
  12. UriInterface $baseApiUri = null 
  13. ) { 
  14. parent::__construct($credentials, $httpClient, $storage, $signature, $baseApiUri); 
  15.  
  16. if (null === $baseApiUri) { 
  17. $this->baseApiUri = new Uri('https://api.twitter.com/1.1/'); 
  18.  
  19. /** 
  20. * {@inheritdoc} 
  21. */ 
  22. public function getRequestTokenEndpoint() 
  23. return new Uri('https://api.twitter.com/oauth/request_token'); 
  24.  
  25. /** 
  26. * {@inheritdoc} 
  27. */ 
  28. public function getAuthorizationEndpoint() 
  29. if ($this->authorizationEndpoint != self::ENDPOINT_AUTHENTICATE 
  30. && $this->authorizationEndpoint != self::ENDPOINT_AUTHORIZE) { 
  31. $this->authorizationEndpoint = self::ENDPOINT_AUTHENTICATE; 
  32. return new Uri($this->authorizationEndpoint); 
  33.  
  34. /** 
  35. * @param string $authorizationEndpoint 
  36. * @throws Exception 
  37. */ 
  38. public function setAuthorizationEndpoint($endpoint) 
  39. if ($endpoint != self::ENDPOINT_AUTHENTICATE && $endpoint != self::ENDPOINT_AUTHORIZE) { 
  40. throw new Exception( 
  41. sprintf("'%s' is not a correct Twitter authorization endpoint.", $endpoint) 
  42. ); 
  43. $this->authorizationEndpoint = $endpoint; 
  44.  
  45. /** 
  46. * {@inheritdoc} 
  47. */ 
  48. public function getAccessTokenEndpoint() 
  49. return new Uri('https://api.twitter.com/oauth/access_token'); 
  50.  
  51. /** 
  52. * {@inheritdoc} 
  53. */ 
  54. protected function parseRequestTokenResponse($responseBody) 
  55. parse_str($responseBody, $data); 
  56.  
  57. if (null === $data || !is_array($data)) { 
  58. throw new TokenResponseException('Unable to parse response.'); 
  59. } elseif (!isset($data['oauth_callback_confirmed']) || $data['oauth_callback_confirmed'] !== 'true') { 
  60. throw new TokenResponseException('Error in retrieving token.'); 
  61.  
  62. return $this->parseAccessTokenResponse($responseBody); 
  63.  
  64. /** 
  65. * {@inheritdoc} 
  66. */ 
  67. protected function parseAccessTokenResponse($responseBody) 
  68. parse_str($responseBody, $data); 
  69.  
  70. if (null === $data || !is_array($data)) { 
  71. throw new TokenResponseException('Unable to parse response.'); 
  72. } elseif (isset($data['error'])) { 
  73. throw new TokenResponseException('Error in retrieving token: "' . $data['error'] . '"'); 
  74.  
  75. $token = new StdOAuth1Token(); 
  76.  
  77. $token->setRequestToken($data['oauth_token']); 
  78. $token->setRequestTokenSecret($data['oauth_token_secret']); 
  79. $token->setAccessToken($data['oauth_token']); 
  80. $token->setAccessTokenSecret($data['oauth_token_secret']); 
  81.  
  82. $token->setEndOfLife(StdOAuth1Token::EOL_NEVER_EXPIRES); 
  83. unset($data['oauth_token'], $data['oauth_token_secret']); 
  84. $token->setExtraParams($data); 
  85.  
  86. return $token;