Verzeichnisstruktur phpBB-3.2.0


Veröffentlicht
06.01.2017

So funktioniert es


Auf das letzte Element klicken. Dies geht jeweils ein Schritt zurück

Auf das Icon klicken, dies öffnet das Verzeichnis. Nochmal klicken schließt das Verzeichnis.
Auf den Verzeichnisnamen klicken, dies zeigt nur das Verzeichnis mit Inhalt an

      (Beispiel Datei-Icons)

Auf das Icon klicken um den Quellcode anzuzeigen

Spotify.php

Zuletzt modifiziert: 09.10.2024, 12:59 - Dateigröße: 3.17 KiB


 001  <?php
 002   
 003  namespace OAuth\OAuth2\Service;
 004   
 005  use OAuth\OAuth2\Token\StdOAuth2Token;
 006  use OAuth\Common\Http\Exception\TokenResponseException;
 007  use OAuth\Common\Http\Uri\Uri;
 008  use OAuth\Common\Consumer\CredentialsInterface;
 009  use OAuth\Common\Http\Client\ClientInterface;
 010  use OAuth\Common\Storage\TokenStorageInterface;
 011  use OAuth\Common\Http\Uri\UriInterface;
 012   
 013  class Spotify extends AbstractService
 014  {
 015      /**
 016       * Scopes
 017       *
 018       * @var string
 019       */
 020      const SCOPE_PLAYLIST_MODIFY_PUBLIC = 'playlist-modify-public';
 021      const SCOPE_PLAYLIST_MODIFY_PRIVATE = 'playlist-modify-private';
 022      const SCOPE_PLAYLIST_READ_PRIVATE = 'playlist-read-private';
 023      const SCOPE_PLAYLIST_READ_COLABORATIVE = 'playlist-read-collaborative';
 024      const SCOPE_STREAMING = 'streaming';
 025      const SCOPE_USER_LIBRARY_MODIFY = 'user-library-modify';
 026      const SCOPE_USER_LIBRARY_READ = 'user-library-read';
 027      const SCOPE_USER_READ_PRIVATE = 'user-read-private';
 028      const SCOPE_USER_READ_EMAIL = 'user-read-email';
 029      const SCOPE_USER_READ_BIRTHDAY = 'user-read-birthdate';
 030      const SCOPE_USER_READ_FOLLOW = 'user-follow-read';
 031   
 032      public function __construct(
 033          CredentialsInterface $credentials,
 034          ClientInterface $httpClient,
 035          TokenStorageInterface $storage,
 036          $scopes = array(),
 037          UriInterface $baseApiUri = null
 038      ) {
 039          parent::__construct($credentials, $httpClient, $storage, $scopes, $baseApiUri, true);
 040   
 041          if (null === $baseApiUri) {
 042              $this->baseApiUri = new Uri('https://api.spotify.com/v1/');
 043          }
 044      }
 045   
 046      /**
 047       * {@inheritdoc}
 048       */
 049      public function getAuthorizationEndpoint()
 050      {
 051          return new Uri('https://accounts.spotify.com/authorize');
 052      }
 053   
 054      /**
 055       * {@inheritdoc}
 056       */
 057      public function getAccessTokenEndpoint()
 058      {
 059          return new Uri('https://accounts.spotify.com/api/token');
 060      }
 061   
 062      /**
 063       * {@inheritdoc}
 064       */
 065      protected function getAuthorizationMethod()
 066      {
 067          return static::AUTHORIZATION_METHOD_HEADER_BEARER;
 068      }
 069   
 070      /**
 071       * {@inheritdoc}
 072       */
 073      protected function parseAccessTokenResponse($responseBody)
 074      {
 075          $data = json_decode($responseBody, true);
 076   
 077          if (null === $data || !is_array($data)) {
 078              throw new TokenResponseException('Unable to parse response.');
 079          } elseif (isset($data['error'])) {
 080              throw new TokenResponseException('Error in retrieving token: "' . $data['error'] . '"');
 081          }
 082   
 083   
 084          $token = new StdOAuth2Token();
 085          $token->setAccessToken($data['access_token']);
 086   
 087          if (isset($data['expires_in'])) {
 088              $token->setLifetime($data['expires_in']);
 089              unset($data['expires_in']);
 090          }
 091   
 092          if (isset($data['refresh_token'])) {
 093              $token->setRefreshToken($data['refresh_token']);
 094              unset($data['refresh_token']);
 095          }
 096   
 097          unset($data['access_token']);
 098   
 099          $token->setExtraParams($data);
 100   
 101          return $token;
 102      }
 103   
 104      /**
 105       * {@inheritdoc}
 106       */
 107      protected function getExtraOAuthHeaders()
 108      {
 109          return array('Authorization' => 'Basic ' .
 110              base64_encode($this->credentials->getConsumerId() . ':' . $this->credentials->getConsumerSecret()));
 111      }
 112  }
 113