Una.php 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <?php
  2. /**
  3. * Copyright (c) BoonEx Pty Limited - http://www.boonex.com/
  4. * CC-BY License - http://creativecommons.org/licenses/by/3.0/
  5. *
  6. * @defgroup TridentStudio Trident Studio
  7. * @{
  8. */
  9. namespace OAuth\OAuth1\Service;
  10. use OAuth\OAuth1\Signature\SignatureInterface;
  11. use OAuth\OAuth1\Token\StdOAuth1Token;
  12. use OAuth\Common\Http\Exception\TokenResponseException;
  13. use OAuth\Common\Http\Uri\Uri;
  14. use OAuth\Common\Consumer\CredentialsInterface;
  15. use OAuth\Common\Http\Uri\UriInterface;
  16. use OAuth\Common\Storage\TokenStorageInterface;
  17. use OAuth\Common\Http\Client\ClientInterface;
  18. use OAuth\Common\Exception\Exception;
  19. class Trident extends AbstractService
  20. {
  21. public function __construct(CredentialsInterface $credentials, ClientInterface $httpClient, TokenStorageInterface $storage, SignatureInterface $signature, UriInterface $baseApiUri = null) {
  22. parent::__construct($credentials, $httpClient, $storage, $signature, $baseApiUri);
  23. if($baseApiUri === null)
  24. $this->baseApiUri = new Uri(BX_DOL_OAUTH_URL_BASE);
  25. }
  26. /**
  27. * {@inheritdoc}
  28. */
  29. public function getRequestTokenEndpoint()
  30. {
  31. return new Uri(BX_DOL_OAUTH_URL_REQUEST_TOKEN);
  32. }
  33. /**
  34. * {@inheritdoc}
  35. */
  36. public function getAuthorizationEndpoint()
  37. {
  38. return new Uri(BX_DOL_OAUTH_URL_AUTHORIZE);
  39. }
  40. /**
  41. * {@inheritdoc}
  42. */
  43. public function getAccessTokenEndpoint()
  44. {
  45. return new Uri(BX_DOL_OAUTH_URL_ACCESS_TOKEN);
  46. }
  47. /**
  48. * {@inheritdoc}
  49. */
  50. protected function parseRequestTokenResponse($sResponseBody)
  51. {
  52. $aData = array();
  53. parse_str($sResponseBody, $aData);
  54. if($aData === null || !is_array($aData))
  55. throw new TokenResponseException('Unable to parse response.');
  56. return $this->parseAccessTokenResponse($sResponseBody);
  57. }
  58. /**
  59. * {@inheritdoc}
  60. */
  61. protected function parseAccessTokenResponse($sResponseBody)
  62. {
  63. $aData = array();
  64. parse_str($sResponseBody, $aData);
  65. if($aData === null || !is_array($aData))
  66. throw new TokenResponseException('Unable to parse response.');
  67. else if(isset($aData['oauth_err_code']) && isset($aData['oauth_err_message']))
  68. throw new TokenResponseException($aData['oauth_err_message']);
  69. $oToken = new StdOAuth1Token();
  70. $oToken->setRequestToken($aData['oauth_token']);
  71. $oToken->setRequestTokenSecret($aData['oauth_token_secret']);
  72. $oToken->setAccessToken($aData['oauth_token']);
  73. $oToken->setAccessTokenSecret($aData['oauth_token_secret']);
  74. $oToken->setEndOfLife(StdOAuth1Token::EOL_NEVER_EXPIRES);
  75. unset($aData['oauth_token'], $aData['oauth_token_secret']);
  76. $oToken->setExtraParams($aData);
  77. return $oToken;
  78. }
  79. }
  80. /** @} */