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 |
Hubic.php
001 <?php
002 /**
003 * Hubic 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://api.hubic.com/docs/
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 * Hubic 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://api.hubic.com/docs/
028 */
029 class Hubic extends AbstractService
030 {
031 // Scopes
032 const SCOPE_USAGE_GET = 'usage.r';
033 const SCOPE_ACCOUNT_GET = 'account.r';
034 const SCOPE_GETALLLINKS_GET = 'getAllLinks.r';
035 const SCOPE_CREDENTIALS_GET = 'credentials.r';
036 const SCOPE_SPONSORCODE_GET = 'sponsorCode.r';
037 const SCOPE_ACTIVATE_POST = 'activate.w';
038 const SCOPE_SPONSORED_GET = 'sponsored.r';
039 const SCOPE_LINKS_GET = 'links.r';
040 const SCOPE_LINKS_POST = 'links.rw';
041 const SCOPE_LINKS_ALL = 'links.drw';
042
043 public function __construct(
044 CredentialsInterface $credentials,
045 ClientInterface $httpClient,
046 TokenStorageInterface $storage,
047 $scopes = [],
048 ?UriInterface $baseApiUri = null
049 ) {
050 parent::__construct(
051 $credentials,
052 $httpClient,
053 $storage,
054 $scopes,
055 $baseApiUri,
056 true
057 );
058
059 if (null === $baseApiUri) {
060 $this->baseApiUri = new Uri('https://api.hubic.com/');
061 }
062 }
063
064 /**
065 * {@inheritdoc}
066 */
067 public function getAuthorizationEndpoint()
068 {
069 return new Uri('https://api.hubic.com/oauth/auth');
070 }
071
072 /**
073 * {@inheritdoc}
074 */
075 public function getAccessTokenEndpoint()
076 {
077 return new Uri('https://api.hubic.com/oauth/token');
078 }
079
080 /**
081 * {@inheritdoc}
082 */
083 protected function getAuthorizationMethod()
084 {
085 return static::AUTHORIZATION_METHOD_HEADER_BEARER;
086 }
087
088 /**
089 * {@inheritdoc}
090 */
091 protected function parseAccessTokenResponse($responseBody)
092 {
093 $data = json_decode($responseBody, true);
094
095 if (null === $data || !is_array($data)) {
096 throw new TokenResponseException('Unable to parse response.');
097 } elseif (isset($data['error'])) {
098 throw new TokenResponseException(
099 'Error in retrieving token: "' . $data['error'] . '"'
100 );
101 }
102
103 $token = new StdOAuth2Token();
104 $token->setAccessToken($data['access_token']);
105 $token->setLifetime($data['expires_in']);
106
107 if (isset($data['refresh_token'])) {
108 $token->setRefreshToken($data['refresh_token']);
109 unset($data['refresh_token']);
110 }
111
112 unset($data['access_token'], $data['expires_in']);
113
114 $token->setExtraParams($data);
115
116 return $token;
117 }
118
119 /**
120 * {@inheritdoc}
121 */
122 public function getAuthorizationUri(array $additionalParameters = [])
123 {
124 $parameters = array_merge(
125 $additionalParameters,
126 [
127 'type' => 'web_server',
128 'client_id' => $this->credentials->getConsumerId(),
129 'redirect_uri' => $this->credentials->getCallbackUrl(),
130 'response_type' => 'code',
131 ]
132 );
133
134 // special, hubic use a param scope with commas
135 // between scopes instead of spaces
136 $parameters['scope'] = implode(',', $this->scopes);
137
138 if ($this->needsStateParameterInAuthUrl()) {
139 if (!isset($parameters['state'])) {
140 $parameters['state'] = $this->generateAuthorizationState();
141 }
142 $this->storeAuthorizationState($parameters['state']);
143 }
144
145 // Build the url
146 $url = clone $this->getAuthorizationEndpoint();
147 foreach ($parameters as $key => $val) {
148 $url->addToQuery($key, $val);
149 }
150
151 return $url;
152 }
153 }
154