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

Strava.php

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


 001  <?php
 002  /**
 003   * Strava service.
 004   *
 005   * @author  Pedro Amorim <contact@pamorim.fr>
 006   * @license http://www.opensource.org/licenses/mit-license.html MIT License
 007   * @link    http://strava.github.io/
 008   * @link    http://strava.github.io/api/v3/oauth/
 009   */
 010   
 011  namespace OAuth\OAuth2\Service;
 012   
 013  use OAuth\OAuth2\Token\StdOAuth2Token;
 014  use OAuth\Common\Http\Exception\TokenResponseException;
 015  use OAuth\Common\Http\Uri\Uri;
 016  use OAuth\Common\Consumer\CredentialsInterface;
 017  use OAuth\Common\Http\Client\ClientInterface;
 018  use OAuth\Common\Storage\TokenStorageInterface;
 019  use OAuth\Common\Http\Uri\UriInterface;
 020  use OAuth\OAuth2\Service\Exception\InvalidAccessTypeException;
 021   
 022  /**
 023   * Strava service.
 024   *
 025   * @author  Pedro Amorim <contact@pamorim.fr>
 026   * @license http://www.opensource.org/licenses/mit-license.html MIT License
 027   * @link    http://strava.github.io/
 028   * @link    http://strava.github.io/api/v3/oauth/
 029   */
 030  class Strava extends AbstractService
 031  {
 032      /**
 033       * Scopes
 034       */
 035      // default
 036      const SCOPE_PUBLIC       = 'public';
 037      // Modify activities, upload on the user’s behalf
 038      const SCOPE_WRITE        = 'write';
 039      // View private activities and data within privacy zones
 040      const SCOPE_VIEW_PRIVATE = 'view_private';
 041   
 042      protected $approvalPrompt = 'auto';
 043   
 044      public function __construct(
 045          CredentialsInterface $credentials,
 046          ClientInterface $httpClient,
 047          TokenStorageInterface $storage,
 048          $scopes = array(),
 049          UriInterface $baseApiUri = null
 050      ) {
 051          if (empty($scopes)) {
 052              $scopes = array(self::SCOPE_PUBLIC);
 053          }
 054   
 055          parent::__construct(
 056              $credentials,
 057              $httpClient,
 058              $storage,
 059              $scopes,
 060              $baseApiUri,
 061              true
 062          );
 063   
 064          if (null === $baseApiUri) {
 065              $this->baseApiUri = new Uri('https://www.strava.com/api/v3/');
 066          }
 067      }
 068   
 069      /**
 070       * {@inheritdoc}
 071       */
 072      public function getAuthorizationEndpoint()
 073      {
 074          return new Uri('https://www.strava.com/oauth/authorize?approval_prompt=' . $this->approvalPrompt);
 075      }
 076   
 077      /**
 078       * {@inheritdoc}
 079       */
 080      public function getAccessTokenEndpoint()
 081      {
 082          return new Uri('https://www.strava.com/oauth/token');
 083      }
 084   
 085      /**
 086       * {@inheritdoc}
 087       */
 088      protected function getAuthorizationMethod()
 089      {
 090          return static::AUTHORIZATION_METHOD_HEADER_BEARER;
 091      }
 092   
 093      /**
 094       * {@inheritdoc}
 095       */
 096      protected function parseAccessTokenResponse($responseBody)
 097      {
 098          $data = json_decode($responseBody, true);
 099   
 100          if (null === $data || !is_array($data)) {
 101              throw new TokenResponseException('Unable to parse response.');
 102          } elseif (isset($data['error_description'])) {
 103              throw new TokenResponseException(
 104                  'Error in retrieving token: "' . $data['error_description'] . '"'
 105              );
 106          } elseif (isset($data['error'])) {
 107              throw new TokenResponseException(
 108                  'Error in retrieving token: "' . $data['error'] . '"'
 109              );
 110          }
 111   
 112          $token = new StdOAuth2Token();
 113          $token->setAccessToken($data['access_token']);
 114   
 115          if (isset($data['expires_in'])) {
 116              $token->setLifeTime($data['expires_in']);
 117              unset($data['expires_in']);
 118          }
 119          if (isset($data['refresh_token'])) {
 120              $token->setRefreshToken($data['refresh_token']);
 121              unset($data['refresh_token']);
 122          }
 123   
 124          unset($data['access_token']);
 125   
 126          $token->setExtraParams($data);
 127   
 128          return $token;
 129      }
 130   
 131      public function setApprouvalPrompt($prompt)
 132      {
 133          if (!in_array($prompt, array('auto', 'force'), true)) {
 134              // @todo Maybe could we rename this exception
 135              throw new InvalidAccessTypeException('Invalid approuvalPrompt, expected either auto or force.');
 136          }
 137          $this->approvalPrompt = $prompt;
 138      }
 139   
 140      /**
 141       * {@inheritdoc}
 142       */
 143      protected function getScopesDelimiter()
 144      {
 145          return ',';
 146      }
 147  }
 148