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

Hubic.php

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


001  <?php
002  /**
003   * Hubic service.
004   *
005   * @author  Pedro Amorim <contact@pamorim.fr>
006   * @license http://www.opensource.org/licenses/mit-license.html MIT License
007   * @link    https://api.hubic.com/docs/
008   */
009   
010  namespace OAuth\OAuth2\Service;
011   
012  use OAuth\OAuth2\Token\StdOAuth2Token;
013  use OAuth\Common\Http\Exception\TokenResponseException;
014  use OAuth\Common\Http\Uri\Uri;
015  use OAuth\Common\Consumer\CredentialsInterface;
016  use OAuth\Common\Http\Client\ClientInterface;
017  use OAuth\Common\Storage\TokenStorageInterface;
018  use OAuth\Common\Http\Uri\UriInterface;
019   
020  /**
021   * Hubic service.
022   *
023   * @author  Pedro Amorim <contact@pamorim.fr>
024   * @license http://www.opensource.org/licenses/mit-license.html MIT License
025   * @link    https://api.hubic.com/docs/
026   */
027  class Hubic extends AbstractService
028  {
029   
030      // Scopes
031      const SCOPE_USAGE_GET       = 'usage.r';
032      const SCOPE_ACCOUNT_GET     = 'account.r';
033      const SCOPE_GETALLLINKS_GET = 'getAllLinks.r';
034      const SCOPE_CREDENTIALS_GET = 'credentials.r';
035      const SCOPE_SPONSORCODE_GET = 'sponsorCode.r';
036      const SCOPE_ACTIVATE_POST   = 'activate.w';
037      const SCOPE_SPONSORED_GET   = 'sponsored.r';
038      const SCOPE_LINKS_GET       = 'links.r';
039      const SCOPE_LINKS_POST      = 'links.rw';
040      const SCOPE_LINKS_ALL       = 'links.drw';
041   
042      public function __construct(
043          CredentialsInterface $credentials,
044          ClientInterface $httpClient,
045          TokenStorageInterface $storage,
046          $scopes = array(),
047          UriInterface $baseApiUri = null
048      ) {
049          parent::__construct(
050              $credentials,
051              $httpClient,
052              $storage,
053              $scopes,
054              $baseApiUri,
055              true
056          );
057   
058          if (null === $baseApiUri) {
059              $this->baseApiUri = new Uri('https://api.hubic.com/');
060          }
061      }
062   
063      /**
064       * {@inheritdoc}
065       */
066      public function getAuthorizationEndpoint()
067      {
068          return new Uri('https://api.hubic.com/oauth/auth');
069   
070      }
071   
072      /**
073       * {@inheritdoc}
074       */
075      public function getAccessTokenEndpoint()
076      {
077          return new Uri('https://api.hubic.com/oauth/token');
078      }
079   
080      /**
081       * {@inheritdoc}
082       */
083      protected function getAuthorizationMethod()
084      {
085          return static::AUTHORIZATION_METHOD_HEADER_BEARER;
086      }
087   
088      /**
089       * {@inheritdoc}
090       */
091      protected function parseAccessTokenResponse($responseBody)
092      {
093          $data = json_decode($responseBody, true);
094   
095          if (null === $data || !is_array($data)) {
096              throw new TokenResponseException('Unable to parse response.');
097          } elseif (isset($data['error'])) {
098              throw new TokenResponseException(
099                  'Error in retrieving token: "' . $data['error'] . '"'
100              );
101          }
102   
103          $token = new StdOAuth2Token();
104          $token->setAccessToken($data['access_token']);
105          $token->setLifetime($data['expires_in']);
106   
107          if (isset($data['refresh_token'])) {
108              $token->setRefreshToken($data['refresh_token']);
109              unset($data['refresh_token']);
110          }
111   
112          unset($data['access_token']);
113          unset($data['expires_in']);
114   
115          $token->setExtraParams($data);
116   
117          return $token;
118      }
119   
120   
121      /**
122       * {@inheritdoc}
123       */
124      public function getAuthorizationUri(array $additionalParameters = array())
125      {
126          $parameters = array_merge(
127              $additionalParameters,
128              array(
129                  'type'          => 'web_server',
130                  'client_id'     => $this->credentials->getConsumerId(),
131                  'redirect_uri'  => $this->credentials->getCallbackUrl(),
132                  'response_type' => 'code',
133              )
134          );
135   
136          // special, hubic use a param scope with commas
137          // between scopes instead of spaces
138          $parameters['scope'] = implode(',', $this->scopes);
139   
140          if ($this->needsStateParameterInAuthUrl()) {
141              if (!isset($parameters['state'])) {
142                  $parameters['state'] = $this->generateAuthorizationState();
143              }
144              $this->storeAuthorizationState($parameters['state']);
145          }
146   
147          // Build the url
148          $url = clone $this->getAuthorizationEndpoint();
149          foreach ($parameters as $key => $val) {
150              $url->addToQuery($key, $val);
151          }
152   
153          return $url;
154      }
155  }
156