Verzeichnisstruktur phpBB-3.1.0


Veröffentlicht
27.10.2014

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

Amazon.php

Zuletzt modifiziert: 09.10.2024, 12:58 - Dateigröße: 3.04 KiB


01  <?php
02  namespace OAuth\OAuth2\Service;
03   
04  use OAuth\OAuth2\Token\StdOAuth2Token;
05  use OAuth\Common\Http\Exception\TokenResponseException;
06  use OAuth\Common\Http\Uri\Uri;
07  use OAuth\Common\Consumer\Credentials;
08  use OAuth\Common\Http\Client\ClientInterface;
09  use OAuth\Common\Storage\TokenStorageInterface;
10  use OAuth\Common\Http\Uri\UriInterface;
11   
12  /**
13   * Amazon service.
14   *
15   * @author Flávio Heleno <flaviohbatista@gmail.com>
16   * @link https://images-na.ssl-images-amazon.com/images/G/01/lwa/dev/docs/website-developer-guide._TTH_.pdf
17   */
18  class Amazon extends AbstractService
19  {
20      /**
21       * Defined scopes
22       * @link https://images-na.ssl-images-amazon.com/images/G/01/lwa/dev/docs/website-developer-guide._TTH_.pdf
23       */
24   
25      const SCOPE_PROFILE          = 'profile';
26      const SCOPE_POSTAL_CODE            = 'postal_code';
27   
28      public function __construct(Credentials $credentials, ClientInterface $httpClient, TokenStorageInterface $storage, $scopes = array(), UriInterface $baseApiUri = null)
29      {
30          parent::__construct($credentials, $httpClient, $storage, $scopes, $baseApiUri);
31          if( null === $baseApiUri ) {
32              $this->baseApiUri = new Uri('https://api.amazon.com/');
33          }
34      }
35   
36      /**
37       * @return \OAuth\Common\Http\Uri\UriInterface
38       */
39      public function getAuthorizationEndpoint()
40      {
41          return new Uri('https://www.amazon.com/ap/oa');
42      }
43   
44      /**
45       * @return \OAuth\Common\Http\Uri\UriInterface
46       */
47      public function getAccessTokenEndpoint()
48      {
49          return new Uri('https://www.amazon.com/ap/oatoken');
50      }
51   
52      /**
53       * Returns a class constant from ServiceInterface defining the authorization method used for the API
54       * Header is the sane default.
55       *
56       * @return int
57       */
58      protected function getAuthorizationMethod()
59      {
60          return static::AUTHORIZATION_METHOD_HEADER_BEARER;
61      }
62   
63      /**
64       * @param string $responseBody
65       * @return \OAuth\Common\Token\TokenInterface|\OAuth\OAuth2\Token\StdOAuth2Token
66       * @throws \OAuth\Common\Http\Exception\TokenResponseException
67       */
68      protected function parseAccessTokenResponse($responseBody)
69      {
70          $data = json_decode( $responseBody, true );
71   
72          if( null === $data || !is_array($data) ) {
73              throw new TokenResponseException('Unable to parse response.');
74          } elseif( isset($data['error_description'] ) ) {
75              throw new TokenResponseException('Error in retrieving token: "' . $data['error_description'] . '"');
76          } elseif( isset($data['error'] ) ) {
77              throw new TokenResponseException('Error in retrieving token: "' . $data['error'] . '"');
78          }
79   
80          $token = new StdOAuth2Token();
81   
82          $token->setAccessToken( $data['access_token'] );
83          $token->setLifeTime( $data['expires_in'] );
84   
85          if( isset($data['refresh_token'] ) ) {
86              $token->setRefreshToken( $data['refresh_token'] );
87              unset($data['refresh_token']);
88          }
89   
90          unset( $data['access_token'] );
91          unset( $data['expires_in'] );
92          $token->setExtraParams( $data );
93   
94          return $token;
95      }
96  }
97