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 |
Pocket.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 Pocket 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 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 = [])
044 {
045 $parameters = array_merge(
046 $additionalParameters,
047 [
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 [
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
086 return $data['code'];
087 }
088
089 public function requestAccessToken($code, $state = null)
090 {
091 $bodyParams = [
092 'consumer_key' => $this->credentials->getConsumerId(),
093 'code' => $code,
094 ];
095
096 $responseBody = $this->httpClient->retrieveResponse(
097 $this->getAccessTokenEndpoint(),
098 $bodyParams,
099 $this->getExtraOAuthHeaders()
100 );
101 $token = $this->parseAccessTokenResponse($responseBody);
102 $this->storage->storeAccessToken($this->service(), $token);
103
104 return $token;
105 }
106
107 protected function parseAccessTokenResponse($responseBody)
108 {
109 parse_str($responseBody, $data);
110
111 if ($data === null || !is_array($data)) {
112 throw new TokenResponseException('Unable to parse response.');
113 } elseif (isset($data['error'])) {
114 throw new TokenResponseException('Error in retrieving token: "' . $data['error'] . '"');
115 }
116
117 $token = new StdOAuth2Token();
118 //$token->setRequestToken($data['access_token']);
119 $token->setAccessToken($data['access_token']);
120 $token->setEndOfLife(StdOAuth2Token::EOL_NEVER_EXPIRES);
121 unset($data['access_token']);
122 $token->setExtraParams($data);
123
124 return $token;
125 }
126 }
127