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

JawboneUP.php

Zuletzt modifiziert: 09.10.2024, 12:59 - Dateigröße: 4.08 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  /**
014   * Jawbone UP service.
015   *
016   * @author Andrii Gakhov <andrii.gakhov@gmail.com>
017   * @link https://jawbone.com/up/developer/authentication
018   */
019  class JawboneUP extends AbstractService
020  {
021      /**
022       * Defined scopes
023       *
024       *
025       * @link https://jawbone.com/up/developer/authentication
026       */
027      // general information scopes
028      const SCOPE_BASIC_READ          = 'basic_read';
029      const SCOPE_EXTENDED_READ       = 'extended_read';
030      const SCOPE_LOCATION_READ       = 'location_read';
031      const SCOPE_FRIENDS_READ        = 'friends_read';
032      // mood scopes
033      const SCOPE_MOOD_READ           = 'mood_read';
034      const SCOPE_MOOD_WRITE          = 'mood_write';
035      // move scopes
036      const SCOPE_MOVE_READ           = 'move_read';
037      const SCOPE_MOVE_WRITE          = 'move_write';
038      // sleep scopes
039      const SCOPE_SLEEP_READ          = 'sleep_read';
040      const SCOPE_SLEEP_WRITE         = 'sleep_write';
041      // meal scopes
042      const SCOPE_MEAL_READ           = 'meal_read';
043      const SCOPE_MEAL_WRITE          = 'meal_write';
044      // weight scopes
045      const SCOPE_WEIGHT_READ         = 'weight_read';
046      const SCOPE_WEIGHT_WRITE        = 'weight_write';
047      // generic event scopes
048      const SCOPE_GENERIC_EVENT_READ  = 'generic_event_read';
049      const SCOPE_GENERIC_EVENT_WRITE = 'generic_event_write';
050   
051   
052      public function __construct(
053          CredentialsInterface $credentials,
054          ClientInterface $httpClient,
055          TokenStorageInterface $storage,
056          $scopes = array(),
057          UriInterface $baseApiUri = null
058      ) {
059          parent::__construct($credentials, $httpClient, $storage, $scopes, $baseApiUri);
060   
061          if (null === $baseApiUri) {
062              $this->baseApiUri = new Uri('https://jawbone.com/nudge/api/v.1.1/');
063          }
064      }
065   
066      /**
067       * {@inheritdoc}
068       */
069      public function getAuthorizationUri(array $additionalParameters = array())
070      {
071          $parameters = array_merge(
072              $additionalParameters,
073              array(
074                  'client_id'     => $this->credentials->getConsumerId(),
075                  'redirect_uri'  => $this->credentials->getCallbackUrl(),
076                  'response_type' => 'code',
077              )
078          );
079   
080          $parameters['scope'] = implode(' ', $this->scopes);
081   
082          // Build the url
083          $url = clone $this->getAuthorizationEndpoint();
084          foreach ($parameters as $key => $val) {
085              $url->addToQuery($key, $val);
086          }
087   
088          return $url;
089      }
090   
091      /**
092       * {@inheritdoc}
093       */
094      public function getAuthorizationEndpoint()
095      {
096          return new Uri('https://jawbone.com/auth/oauth2/auth');
097      }
098   
099      /**
100       * {@inheritdoc}
101       */
102      public function getAccessTokenEndpoint()
103      {
104          return new Uri('https://jawbone.com/auth/oauth2/token');
105      }
106   
107      /**
108       * {@inheritdoc}
109       */
110      protected function getAuthorizationMethod()
111      {
112          return static::AUTHORIZATION_METHOD_HEADER_BEARER;
113      }
114   
115      /**
116       * {@inheritdoc}
117       */
118      protected function parseAccessTokenResponse($responseBody)
119      {
120          $data = json_decode($responseBody, true);
121   
122          if (null === $data || !is_array($data)) {
123              throw new TokenResponseException('Unable to parse response.');
124          } elseif (isset($data['error'])) {
125              throw new TokenResponseException('Error in retrieving token: "' . $data['error'] . '"');
126          }
127   
128          $token = new StdOAuth2Token();
129          $token->setAccessToken($data['access_token']);
130          $token->setLifeTime($data['expires_in']);
131   
132          if (isset($data['refresh_token'])) {
133              $token->setRefreshToken($data['refresh_token']);
134              unset($data['refresh_token']);
135          }
136   
137          unset($data['access_token']);
138          unset($data['expires_in']);
139   
140          $token->setExtraParams($data);
141   
142          return $token;
143      }
144  }
145