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 |
Delicious.php
001 <?php
002 /**
003 * Delicious service.
004 *
005 * @author Pedro Amorim <contact@pamorim.fr>
006 * @license http://www.opensource.org/licenses/mit-license.html MIT License
007 *
008 * @see https://github.com/SciDevs/delicious-api/blob/master/api/oauth.md
009 */
010
011 namespace OAuth\OAuth2\Service;
012
013 use OAuth\Common\Consumer\CredentialsInterface;
014 use OAuth\Common\Http\Client\ClientInterface;
015 use OAuth\Common\Http\Exception\TokenResponseException;
016 use OAuth\Common\Http\Uri\Uri;
017 use OAuth\Common\Http\Uri\UriInterface;
018 use OAuth\Common\Storage\TokenStorageInterface;
019 use OAuth\OAuth2\Token\StdOAuth2Token;
020
021 /**
022 * Delicious service.
023 *
024 * @author Pedro Amorim <contact@pamorim.fr>
025 * @license http://www.opensource.org/licenses/mit-license.html MIT License
026 *
027 * @see https://github.com/SciDevs/delicious-api/blob/master/api/oauth.md
028 */
029 class Delicious extends AbstractService
030 {
031 public function __construct(
032 CredentialsInterface $credentials,
033 ClientInterface $httpClient,
034 TokenStorageInterface $storage,
035 $scopes = [],
036 ?UriInterface $baseApiUri = null
037 ) {
038 parent::__construct(
039 $credentials,
040 $httpClient,
041 $storage,
042 $scopes,
043 $baseApiUri,
044 true
045 );
046
047 if (null === $baseApiUri) {
048 $this->baseApiUri = new Uri('https://api.del.icio.us/v1/');
049 }
050 }
051
052 /**
053 * {@inheritdoc}
054 */
055 public function getAuthorizationEndpoint()
056 {
057 return new Uri('https://delicious.com/auth/authorize');
058 }
059
060 /**
061 * {@inheritdoc}
062 */
063 public function getAccessTokenEndpoint()
064 {
065 return new Uri('https://avosapi.delicious.com/api/v1/oauth/token');
066 }
067
068 /**
069 * {@inheritdoc}
070 */
071 protected function getAuthorizationMethod()
072 {
073 return static::AUTHORIZATION_METHOD_HEADER_BEARER;
074 }
075
076 /**
077 * {@inheritdoc}
078 */
079 protected function parseAccessTokenResponse($responseBody)
080 {
081 $data = json_decode($responseBody, true);
082
083 if (null === $data || !is_array($data)) {
084 throw new TokenResponseException('Unable to parse response.');
085 } elseif (isset($data['error'])) {
086 throw new TokenResponseException(
087 'Error in retrieving token: "' . $data['error'] . '"'
088 );
089 }
090
091 $token = new StdOAuth2Token();
092 $token->setAccessToken($data['access_token']);
093
094 if (isset($data['expires_in'])) {
095 $token->setLifetime($data['expires_in']);
096 unset($data['expires_in']);
097 }
098 if (isset($data['refresh_token'])) {
099 $token->setRefreshToken($data['refresh_token']);
100 unset($data['refresh_token']);
101 }
102
103 unset($data['access_token']);
104
105 $token->setExtraParams($data);
106
107 return $token;
108 }
109
110 // Special, delicious didn't respect the oauth2 RFC and need a grant_type='code'
111
112 /**
113 * {@inheritdoc}
114 */
115 public function requestAccessToken($code, $state = null)
116 {
117 if (null !== $state) {
118 $this->validateAuthorizationState($state);
119 }
120
121 $bodyParams = [
122 'code' => $code,
123 'client_id' => $this->credentials->getConsumerId(),
124 'client_secret' => $this->credentials->getConsumerSecret(),
125 'redirect_uri' => $this->credentials->getCallbackUrl(),
126 'grant_type' => 'code',
127 ];
128
129 $responseBody = $this->httpClient->retrieveResponse(
130 $this->getAccessTokenEndpoint(),
131 $bodyParams,
132 $this->getExtraOAuthHeaders()
133 );
134
135 $token = $this->parseAccessTokenResponse($responseBody);
136 $this->storage->storeAccessToken($this->service(), $token);
137
138 return $token;
139 }
140 }
141