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