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

Pocket.php

Zuletzt modifiziert: 09.10.2024, 12:59 - Dateigröße: 3.78 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\Uri\UriInterface;
010  use OAuth\Common\Storage\TokenStorageInterface;
011  use OAuth\Common\Http\Client\ClientInterface;
012   
013  class Pocket extends AbstractService
014  {
015      public function __construct(
016          CredentialsInterface $credentials,
017          ClientInterface $httpClient,
018          TokenStorageInterface $storage,
019          $scopes = array(),
020          UriInterface $baseApiUri = null
021      ) {
022          parent::__construct($credentials, $httpClient, $storage, $scopes, $baseApiUri);
023          if ($baseApiUri === null) {
024              $this->baseApiUri = new Uri('https://getpocket.com/v3/');
025          }
026      }
027      
028      public function getRequestTokenEndpoint()
029      {
030          return new Uri('https://getpocket.com/v3/oauth/request');
031      }
032      
033      public function getAuthorizationEndpoint()
034      {
035          return new Uri('https://getpocket.com/auth/authorize');
036      }
037      
038      public function getAccessTokenEndpoint()
039      {
040          return new Uri('https://getpocket.com/v3/oauth/authorize');
041      }
042      
043      public function getAuthorizationUri(array $additionalParameters = array())
044      {
045          $parameters = array_merge(
046              $additionalParameters,
047              array(
048                  'redirect_uri' => $this->credentials->getCallbackUrl(),
049              )
050          );
051          
052          // Build the url
053          $url = clone $this->getAuthorizationEndpoint();
054          foreach ($parameters as $key => $val) {
055              $url->addToQuery($key, $val);
056          }
057   
058          return $url;
059      }
060      
061      public function requestRequestToken()
062      {
063          $responseBody = $this->httpClient->retrieveResponse(
064              $this->getRequestTokenEndpoint(),
065              array(
066                  'consumer_key' => $this->credentials->getConsumerId(),
067                  'redirect_uri' => $this->credentials->getCallbackUrl(),
068              )
069          );
070          
071          $code = $this->parseRequestTokenResponse($responseBody);
072   
073          return $code;
074      }
075      
076      protected function parseRequestTokenResponse($responseBody)
077      {
078          parse_str($responseBody, $data);
079          
080          if (null === $data || !is_array($data)) {
081              throw new TokenResponseException('Unable to parse response.');
082          } elseif (!isset($data['code'])) {
083              throw new TokenResponseException('Error in retrieving code.');
084          }
085          return $data['code'];
086      }
087      
088      public function requestAccessToken($code)
089      {
090          $bodyParams = array(
091              'consumer_key'     => $this->credentials->getConsumerId(),
092              'code'             => $code,
093          );
094   
095          $responseBody = $this->httpClient->retrieveResponse(
096              $this->getAccessTokenEndpoint(),
097              $bodyParams,
098              $this->getExtraOAuthHeaders()
099          );
100          $token = $this->parseAccessTokenResponse($responseBody);
101          $this->storage->storeAccessToken($this->service(), $token);
102   
103          return $token;
104      }
105      
106      protected function parseAccessTokenResponse($responseBody)
107      {
108          parse_str($responseBody, $data);
109          
110          if ($data === null || !is_array($data)) {
111              throw new TokenResponseException('Unable to parse response.');
112          } elseif (isset($data['error'])) {
113              throw new TokenResponseException('Error in retrieving token: "' . $data['error'] . '"');
114          }
115          
116          $token = new StdOAuth2Token();
117          #$token->setRequestToken($data['access_token']);
118          $token->setAccessToken($data['access_token']);
119          $token->setEndOfLife(StdOAuth2Token::EOL_NEVER_EXPIRES);
120          unset($data['access_token']);
121          $token->setExtraParams($data);
122          
123          return $token;
124      }
125  }
126