[ Index ]

PHP Cross Reference of phpBB-3.3.14-deutsch

title

Body

[close]

/vendor/carlos-mg89/oauth/src/OAuth/OAuth2/Service/ -> SoundCloud.php (source)

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


Generated: Mon Nov 25 19:05:08 2024 Cross-referenced by PHPXref 0.7.1