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 |
Twitter.php
001 <?php
002
003 namespace OAuth\OAuth1\Service;
004
005 use OAuth\Common\Consumer\CredentialsInterface;
006 use OAuth\Common\Exception\Exception;
007 use OAuth\Common\Http\Client\ClientInterface;
008 use OAuth\Common\Http\Exception\TokenResponseException;
009 use OAuth\Common\Http\Uri\Uri;
010 use OAuth\Common\Http\Uri\UriInterface;
011 use OAuth\Common\Storage\TokenStorageInterface;
012 use OAuth\OAuth1\Signature\SignatureInterface;
013 use OAuth\OAuth1\Token\StdOAuth1Token;
014
015 class Twitter extends AbstractService
016 {
017 const ENDPOINT_AUTHENTICATE = 'https://api.twitter.com/oauth/authenticate';
018 const ENDPOINT_AUTHORIZE = 'https://api.twitter.com/oauth/authorize';
019
020 protected $authorizationEndpoint = self::ENDPOINT_AUTHENTICATE;
021
022 public function __construct(
023 CredentialsInterface $credentials,
024 ClientInterface $httpClient,
025 TokenStorageInterface $storage,
026 SignatureInterface $signature,
027 ?UriInterface $baseApiUri = null
028 ) {
029 parent::__construct($credentials, $httpClient, $storage, $signature, $baseApiUri);
030
031 if (null === $baseApiUri) {
032 $this->baseApiUri = new Uri('https://api.twitter.com/1.1/');
033 }
034 }
035
036 /**
037 * {@inheritdoc}
038 */
039 public function getRequestTokenEndpoint()
040 {
041 return new Uri('https://api.twitter.com/oauth/request_token');
042 }
043
044 /**
045 * {@inheritdoc}
046 */
047 public function getAuthorizationEndpoint()
048 {
049 if ($this->authorizationEndpoint != self::ENDPOINT_AUTHENTICATE
050 && $this->authorizationEndpoint != self::ENDPOINT_AUTHORIZE) {
051 $this->authorizationEndpoint = self::ENDPOINT_AUTHENTICATE;
052 }
053
054 return new Uri($this->authorizationEndpoint);
055 }
056
057 /**
058 * @param mixed $endpoint
059 */
060 public function setAuthorizationEndpoint($endpoint): void
061 {
062 if ($endpoint != self::ENDPOINT_AUTHENTICATE && $endpoint != self::ENDPOINT_AUTHORIZE) {
063 throw new Exception(
064 sprintf("'%s' is not a correct Twitter authorization endpoint.", $endpoint)
065 );
066 }
067 $this->authorizationEndpoint = $endpoint;
068 }
069
070 /**
071 * {@inheritdoc}
072 */
073 public function getAccessTokenEndpoint()
074 {
075 return new Uri('https://api.twitter.com/oauth/access_token');
076 }
077
078 /**
079 * {@inheritdoc}
080 */
081 protected function parseRequestTokenResponse($responseBody)
082 {
083 parse_str($responseBody, $data);
084
085 if (null === $data || !is_array($data)) {
086 throw new TokenResponseException('Unable to parse response.');
087 } elseif (!isset($data['oauth_callback_confirmed']) || $data['oauth_callback_confirmed'] !== 'true') {
088 throw new TokenResponseException('Error in retrieving token.');
089 }
090
091 return $this->parseAccessTokenResponse($responseBody);
092 }
093
094 /**
095 * {@inheritdoc}
096 */
097 protected function parseAccessTokenResponse($responseBody)
098 {
099 parse_str($responseBody, $data);
100
101 if (null === $data || !is_array($data)) {
102 throw new TokenResponseException('Unable to parse response: ' . $responseBody);
103 } elseif (isset($data['error'])) {
104 throw new TokenResponseException('Error in retrieving token: "' . $data['error'] . '"');
105 } elseif (!isset($data['oauth_token']) || !isset($data['oauth_token_secret'])) {
106 throw new TokenResponseException('Invalid response. OAuth Token data not set: ' . $responseBody);
107 }
108
109 $token = new StdOAuth1Token();
110
111 $token->setRequestToken($data['oauth_token']);
112 $token->setRequestTokenSecret($data['oauth_token_secret']);
113 $token->setAccessToken($data['oauth_token']);
114 $token->setAccessTokenSecret($data['oauth_token_secret']);
115
116 $token->setEndOfLife(StdOAuth1Token::EOL_NEVER_EXPIRES);
117 unset($data['oauth_token'], $data['oauth_token_secret']);
118 $token->setExtraParams($data);
119
120 return $token;
121 }
122 }
123