[ Index ]

PHP Cross Reference of phpBB-3.3.7-deutsch

title

Body

[close]

/vendor/lusitanian/oauth/src/OAuth/OAuth1/Service/ -> Yahoo.php (source)

   1  <?php
   2  
   3  namespace OAuth\OAuth1\Service;
   4  
   5  use OAuth\OAuth1\Signature\SignatureInterface;
   6  use OAuth\OAuth1\Token\StdOAuth1Token;
   7  use OAuth\Common\Http\Exception\TokenResponseException;
   8  use OAuth\Common\Http\Uri\Uri;
   9  use OAuth\Common\Consumer\CredentialsInterface;
  10  use OAuth\Common\Http\Uri\UriInterface;
  11  use OAuth\Common\Storage\TokenStorageInterface;
  12  use OAuth\Common\Http\Client\ClientInterface;
  13  use OAuth\OAuth1\Token\TokenInterface;
  14  
  15  class Yahoo extends AbstractService
  16  {
  17      public function __construct(
  18          CredentialsInterface $credentials,
  19          ClientInterface $httpClient,
  20          TokenStorageInterface $storage,
  21          SignatureInterface $signature,
  22          UriInterface $baseApiUri = null
  23      ) {
  24          parent::__construct($credentials, $httpClient, $storage, $signature, $baseApiUri);
  25  
  26          if (null === $baseApiUri) {
  27              $this->baseApiUri = new Uri('https://social.yahooapis.com/v1/');
  28          }
  29      }
  30  
  31      /**
  32       * {@inheritDoc}
  33       */
  34      public function getRequestTokenEndpoint()
  35      {
  36          return new Uri('https://api.login.yahoo.com/oauth/v2/get_request_token');
  37      }
  38  
  39      /**
  40       * {@inheritdoc}
  41       */
  42      public function getAuthorizationEndpoint()
  43      {
  44          return new Uri('https://api.login.yahoo.com/oauth/v2/request_auth');
  45      }
  46  
  47      /**
  48       * {@inheritdoc}
  49       */
  50      public function getAccessTokenEndpoint()
  51      {
  52          return new Uri('https://api.login.yahoo.com/oauth/v2/get_token');
  53      }
  54  
  55      /**
  56       * {@inheritdoc}
  57       */
  58      public function refreshAccessToken(TokenInterface $token)
  59      {
  60          $extraParams = $token->getExtraParams();
  61          $bodyParams = array('oauth_session_handle' => $extraParams['oauth_session_handle']);
  62  
  63          $authorizationHeader = array(
  64              'Authorization' => $this->buildAuthorizationHeaderForAPIRequest(
  65                  'POST',
  66                  $this->getAccessTokenEndpoint(),
  67                  $this->storage->retrieveAccessToken($this->service()),
  68                  $bodyParams
  69              )
  70          );
  71  
  72  
  73          
  74          $headers = array_merge($authorizationHeader, $this->getExtraOAuthHeaders(), array());
  75  
  76          $responseBody = $this->httpClient->retrieveResponse($this->getAccessTokenEndpoint(), $bodyParams, $headers);
  77  
  78          $token = $this->parseAccessTokenResponse($responseBody);
  79          $this->storage->storeAccessToken($this->service(), $token);
  80  
  81          return $token;
  82      }
  83  
  84      /**
  85       * {@inheritdoc}
  86       */
  87      protected function parseRequestTokenResponse($responseBody)
  88      {
  89          parse_str($responseBody, $data);
  90  
  91          if (null === $data || !is_array($data)) {
  92              throw new TokenResponseException('Unable to parse response.');
  93          } elseif (!isset($data['oauth_callback_confirmed']) || $data['oauth_callback_confirmed'] !== 'true') {
  94              throw new TokenResponseException('Error in retrieving token.');
  95          }
  96  
  97          return $this->parseAccessTokenResponse($responseBody);
  98      }
  99  
 100      /**
 101       * {@inheritdoc}
 102       */
 103      protected function parseAccessTokenResponse($responseBody)
 104      {
 105          parse_str($responseBody, $data);
 106  
 107          if (null === $data || !is_array($data)) {
 108              throw new TokenResponseException('Unable to parse response.');
 109          } elseif (isset($data['error'])) {
 110              throw new TokenResponseException('Error in retrieving token: "' . $data['error'] . '"');
 111          }
 112  
 113          $token = new StdOAuth1Token();
 114  
 115          $token->setRequestToken($data['oauth_token']);
 116          $token->setRequestTokenSecret($data['oauth_token_secret']);
 117          $token->setAccessToken($data['oauth_token']);
 118          $token->setAccessTokenSecret($data['oauth_token_secret']);
 119  
 120          if (isset($data['oauth_expires_in'])) {
 121              $token->setLifetime($data['oauth_expires_in']);
 122          } else {
 123              $token->setEndOfLife(StdOAuth1Token::EOL_NEVER_EXPIRES);
 124          }
 125  
 126          unset($data['oauth_token'], $data['oauth_token_secret']);
 127          $token->setExtraParams($data);
 128  
 129          return $token;
 130      }
 131  }


Generated: Thu Mar 24 21:31:15 2022 Cross-referenced by PHPXref 0.7.1