Verzeichnisstruktur phpBB-3.3.15
- Veröffentlicht
- 28.08.2024
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. |
|
(Beispiel Datei-Icons)
|
Auf das Icon klicken um den Quellcode anzuzeigen |
Mailchimp.php
001 <?php
002
003 namespace OAuth\OAuth2\Service;
004
005 use OAuth\Common\Consumer\CredentialsInterface;
006 use OAuth\Common\Http\Client\ClientInterface;
007 use OAuth\Common\Http\Exception\TokenResponseException;
008 use OAuth\Common\Http\Uri\Uri;
009 use OAuth\Common\Http\Uri\UriInterface;
010 use OAuth\Common\Storage\TokenStorageInterface;
011 use OAuth\OAuth2\Token\StdOAuth2Token;
012
013 class Mailchimp extends AbstractService
014 {
015 public function __construct(
016 CredentialsInterface $credentials,
017 ClientInterface $httpClient,
018 TokenStorageInterface $storage,
019 $scopes = [],
020 ?UriInterface $baseApiUri = null
021 ) {
022 parent::__construct($credentials, $httpClient, $storage, $scopes, $baseApiUri);
023
024 if (null === $this->baseApiUri && $storage->hasAccessToken($this->service())) {
025 $this->setBaseApiUri($storage->retrieveAccessToken($this->service()));
026 }
027 }
028
029 /**
030 * {@inheritdoc}
031 */
032 protected function getAuthorizationMethod()
033 {
034 return static::AUTHORIZATION_METHOD_QUERY_STRING_V3;
035 }
036
037 /**
038 * {@inheritdoc}
039 */
040 public function getAuthorizationEndpoint()
041 {
042 return new Uri('https://login.mailchimp.com/oauth2/authorize');
043 }
044
045 /**
046 * {@inheritdoc}
047 */
048 public function getAccessTokenEndpoint()
049 {
050 return new Uri('https://login.mailchimp.com/oauth2/token');
051 }
052
053 /**
054 * {@inheritdoc}
055 */
056 protected function parseAccessTokenResponse($responseBody)
057 {
058 // Parse JSON
059 $data = json_decode($responseBody, true);
060
061 // Do validation.
062 if (null === $data || !is_array($data)) {
063 throw new TokenResponseException('Unable to parse response.');
064 } elseif (isset($data['error'])) {
065 throw new TokenResponseException('Error in retrieving token: "' . $data['error'] . '"');
066 }
067
068 // Create token object.
069 $token = new StdOAuth2Token($data['access_token']);
070
071 // Set the right API endpoint.
072 $this->setBaseApiUri($token);
073
074 // Mailchimp tokens evidently never expire...
075 $token->setEndOfLife(StdOAuth2Token::EOL_NEVER_EXPIRES);
076
077 return $token;
078 }
079
080 /**
081 * {@inheritdoc}
082 */
083 public function request($path, $method = 'GET', $body = null, array $extraHeaders = [])
084 {
085 if (null === $this->baseApiUri) {
086 $this->setBaseApiUri($this->storage->retrieveAccessToken($this->service()));
087 }
088
089 return parent::request($path, $method, $body, $extraHeaders);
090 }
091
092 /**
093 * Set the right base endpoint.
094 */
095 protected function setBaseApiUri(StdOAuth2Token $token)
096 {
097 // Make request uri.
098 $endpoint = 'https://login.mailchimp.com/oauth2/metadata?oauth_token=' . $token->getAccessToken();
099
100 // Grab meta data about the token.
101 $response = $this->httpClient->retrieveResponse(new Uri($endpoint), [], [], 'GET');
102
103 // Parse JSON.
104 $meta = json_decode($response, true);
105
106 // Set base api uri.
107 $this->baseApiUri = new Uri('https://' . $meta['dc'] . '.api.mailchimp.com/2.0/');
108
109 // Allow chaining.
110 return $this;
111 }
112 }
113