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 |
Vkontakte.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 Vkontakte extends AbstractService
014 {
015 /**
016 * Defined scopes.
017 *
018 * @see http://vk.com/dev/permissions
019 */
020 const SCOPE_EMAIL = 'email';
021 const SCOPE_NOTIFY = 'notify';
022 const SCOPE_FRIENDS = 'friends';
023 const SCOPE_PHOTOS = 'photos';
024 const SCOPE_AUDIO = 'audio';
025 const SCOPE_VIDEO = 'video';
026 const SCOPE_DOCS = 'docs';
027 const SCOPE_NOTES = 'notes';
028 const SCOPE_PAGES = 'pages';
029 const SCOPE_APP_LINK = '';
030 const SCOPE_STATUS = 'status';
031 const SCOPE_OFFERS = 'offers';
032 const SCOPE_QUESTIONS = 'questions';
033 const SCOPE_WALL = 'wall';
034 const SCOPE_GROUPS = 'groups';
035 const SCOPE_MESSAGES = 'messages';
036 const SCOPE_NOTIFICATIONS = 'notifications';
037 const SCOPE_STATS = 'stats';
038 const SCOPE_ADS = 'ads';
039 const SCOPE_OFFLINE = 'offline';
040 const SCOPE_NOHTTPS = 'nohttps';
041
042 public function __construct(
043 CredentialsInterface $credentials,
044 ClientInterface $httpClient,
045 TokenStorageInterface $storage,
046 $scopes = [],
047 ?UriInterface $baseApiUri = null
048 ) {
049 parent::__construct($credentials, $httpClient, $storage, $scopes, $baseApiUri);
050
051 if (null === $baseApiUri) {
052 $this->baseApiUri = new Uri('https://api.vk.com/method/');
053 }
054 }
055
056 /**
057 * {@inheritdoc}
058 */
059 public function getAuthorizationEndpoint()
060 {
061 return new Uri('https://oauth.vk.com/authorize');
062 }
063
064 /**
065 * {@inheritdoc}
066 */
067 public function getAccessTokenEndpoint()
068 {
069 return new Uri('https://oauth.vk.com/access_token');
070 }
071
072 /**
073 * {@inheritdoc}
074 */
075 protected function parseAccessTokenResponse($responseBody)
076 {
077 $data = json_decode($responseBody, true);
078
079 if (null === $data || !is_array($data)) {
080 throw new TokenResponseException('Unable to parse response.');
081 } elseif (isset($data['error'])) {
082 throw new TokenResponseException('Error in retrieving token: "' . $data['error'] . '"');
083 }
084
085 $token = new StdOAuth2Token();
086 $token->setAccessToken($data['access_token']);
087 $token->setLifeTime($data['expires_in']);
088
089 if (isset($data['refresh_token'])) {
090 $token->setRefreshToken($data['refresh_token']);
091 unset($data['refresh_token']);
092 }
093
094 unset($data['access_token'], $data['expires_in']);
095
096 $token->setExtraParams($data);
097
098 return $token;
099 }
100
101 /**
102 * {@inheritdoc}
103 */
104 protected function getAuthorizationMethod()
105 {
106 return static::AUTHORIZATION_METHOD_QUERY_STRING;
107 }
108
109 /**
110 * {@inheritdoc}
111 */
112 public function requestAccessToken($code, $state = null)
113 {
114 if (null !== $state) {
115 $this->validateAuthorizationState($state);
116 }
117
118 $bodyParams = [
119 'code' => $code,
120 'client_id' => $this->credentials->getConsumerId(),
121 'client_secret' => $this->credentials->getConsumerSecret(),
122 'redirect_uri' => $this->credentials->getCallbackUrl(),
123 'grant_type' => 'client_credentials',
124
125 ];
126
127 $responseBody = $this->httpClient->retrieveResponse(
128 $this->getAccessTokenEndpoint(),
129 $bodyParams,
130 $this->getExtraOAuthHeaders()
131 );
132
133 $token = $this->parseAccessTokenResponse($responseBody);
134 $this->storage->storeAccessToken($this->service(), $token);
135
136 return $token;
137 }
138 }
139