[ Index ]

PHP Cross Reference of phpBB-3.3.7-deutsch

title

Body

[close]

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

   1  <?php
   2  
   3  namespace OAuth\OAuth2\Service;
   4  
   5  use OAuth\OAuth2\Token\StdOAuth2Token;
   6  use OAuth\Common\Http\Exception\TokenResponseException;
   7  use OAuth\Common\Http\Uri\Uri;
   8  
   9  class Yahoo extends AbstractService
  10  {
  11  
  12      /**
  13      * {@inheritdoc}
  14      */
  15      public function getAuthorizationEndpoint()
  16      {
  17          return new Uri('https://api.login.yahoo.com/oauth2/request_auth');
  18      }
  19  
  20      /**
  21      * {@inheritdoc}
  22      */
  23      public function getAccessTokenEndpoint()
  24      {
  25          return new Uri('https://api.login.yahoo.com/oauth2/get_token');
  26      }
  27  
  28      /**
  29      * {@inheritdoc}
  30      */
  31      protected function getAuthorizationMethod()
  32      {
  33          return static::AUTHORIZATION_METHOD_HEADER_BEARER;
  34      }
  35  
  36      /**
  37      * {@inheritdoc}
  38      */
  39      protected function parseAccessTokenResponse($responseBody)
  40      {
  41          $data = json_decode($responseBody, true);
  42  
  43          if (null === $data || !is_array($data)) {
  44              throw new TokenResponseException('Unable to parse response.');
  45          } elseif (isset($data['error'])) {
  46              throw new TokenResponseException('Error in retrieving token: "' . $data['error'] . '"');
  47          }
  48  
  49          $token = new StdOAuth2Token();
  50          $token->setAccessToken($data['access_token']);
  51          $token->setLifetime($data['expires_in']);
  52  
  53          if (isset($data['refresh_token'])) {
  54              $token->setRefreshToken($data['refresh_token']);
  55              unset($data['refresh_token']);
  56          }
  57  
  58          unset($data['access_token']);
  59          unset($data['expires_in']);
  60  
  61          $token->setExtraParams($data);
  62  
  63          return $token;
  64      }
  65  
  66      /**
  67      * {@inheritdoc}
  68      */
  69      protected function getExtraOAuthHeaders()
  70      {
  71          $encodedCredentials = base64_encode(
  72              $this->credentials->getConsumerId() . ':' . $this->credentials->getConsumerSecret()
  73          );
  74          return array('Authorization' => 'Basic ' . $encodedCredentials);
  75      }
  76  }


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