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 |
GitHub.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 GitHub extends AbstractService
014 {
015 /**
016 * Defined scopes, see http://developer.github.com/v3/oauth/ for definitions.
017 */
018
019 /**
020 * Public read-only access (includes public user profile info, public repo info, and gists).
021 */
022 const SCOPE_READONLY = '';
023
024 /**
025 * Read/write access to profile info only.
026 *
027 * Includes SCOPE_USER_EMAIL and SCOPE_USER_FOLLOW.
028 */
029 const SCOPE_USER = 'user';
030
031 /**
032 * Read access to a user’s email addresses.
033 */
034 const SCOPE_USER_EMAIL = 'user:email';
035
036 /**
037 * Access to follow or unfollow other users.
038 */
039 const SCOPE_USER_FOLLOW = 'user:follow';
040
041 /**
042 * Read/write access to public repos and organizations.
043 */
044 const SCOPE_PUBLIC_REPO = 'public_repo';
045
046 /**
047 * Read/write access to public and private repos and organizations.
048 *
049 * Includes SCOPE_REPO_STATUS.
050 */
051 const SCOPE_REPO = 'repo';
052
053 /**
054 * Grants access to deployment statuses for public and private repositories.
055 * This scope is only necessary to grant other users or services access to deployment statuses,
056 * without granting access to the code.
057 */
058 const SCOPE_REPO_DEPLOYMENT = 'repo_deployment';
059
060 /**
061 * Read/write access to public and private repository commit statuses. This scope is only necessary to grant other
062 * users or services access to private repository commit statuses without granting access to the code. The repo and
063 * public_repo scopes already include access to commit status for private and public repositories, respectively.
064 */
065 const SCOPE_REPO_STATUS = 'repo:status';
066
067 /**
068 * Delete access to adminable repositories.
069 */
070 const SCOPE_DELETE_REPO = 'delete_repo';
071
072 /**
073 * Read access to a user’s notifications. repo is accepted too.
074 */
075 const SCOPE_NOTIFICATIONS = 'notifications';
076
077 /**
078 * Write access to gists.
079 */
080 const SCOPE_GIST = 'gist';
081
082 /**
083 * Grants read and ping access to hooks in public or private repositories.
084 */
085 const SCOPE_HOOKS_READ = 'read:repo_hook';
086
087 /**
088 * Grants read, write, and ping access to hooks in public or private repositories.
089 */
090 const SCOPE_HOOKS_WRITE = 'write:repo_hook';
091
092 /**
093 * Grants read, write, ping, and delete access to hooks in public or private repositories.
094 */
095 const SCOPE_HOOKS_ADMIN = 'admin:repo_hook';
096
097 /**
098 * Read-only access to organization, teams, and membership.
099 */
100 const SCOPE_ORG_READ = 'read:org';
101
102 /**
103 * Publicize and unpublicize organization membership.
104 */
105 const SCOPE_ORG_WRITE = 'write:org';
106
107 /**
108 * Fully manage organization, teams, and memberships.
109 */
110 const SCOPE_ORG_ADMIN = 'admin:org';
111
112 /**
113 * List and view details for public keys.
114 */
115 const SCOPE_PUBLIC_KEY_READ = 'read:public_key';
116
117 /**
118 * Create, list, and view details for public keys.
119 */
120 const SCOPE_PUBLIC_KEY_WRITE = 'write:public_key';
121
122 /**
123 * Fully manage public keys.
124 */
125 const SCOPE_PUBLIC_KEY_ADMIN = 'admin:public_key';
126
127 public function __construct(
128 CredentialsInterface $credentials,
129 ClientInterface $httpClient,
130 TokenStorageInterface $storage,
131 $scopes = [],
132 ?UriInterface $baseApiUri = null
133 ) {
134 parent::__construct($credentials, $httpClient, $storage, $scopes, $baseApiUri);
135
136 if (null === $baseApiUri) {
137 $this->baseApiUri = new Uri('https://api.github.com/');
138 }
139 }
140
141 /**
142 * {@inheritdoc}
143 */
144 public function getAuthorizationEndpoint()
145 {
146 return new Uri('https://github.com/login/oauth/authorize');
147 }
148
149 /**
150 * {@inheritdoc}
151 */
152 public function getAccessTokenEndpoint()
153 {
154 return new Uri('https://github.com/login/oauth/access_token');
155 }
156
157 /**
158 * {@inheritdoc}
159 */
160 protected function getAuthorizationMethod()
161 {
162 return static::AUTHORIZATION_METHOD_HEADER_TOKEN;
163 }
164
165 /**
166 * {@inheritdoc}
167 */
168 protected function parseAccessTokenResponse($responseBody)
169 {
170 $data = json_decode($responseBody, true);
171
172 if (null === $data || !is_array($data)) {
173 throw new TokenResponseException('Unable to parse response.');
174 } elseif (isset($data['error'])) {
175 throw new TokenResponseException('Error in retrieving token: "' . $data['error'] . '"');
176 }
177
178 $token = new StdOAuth2Token();
179 $token->setAccessToken($data['access_token']);
180 // Github tokens evidently never expire...
181 $token->setEndOfLife(StdOAuth2Token::EOL_NEVER_EXPIRES);
182 unset($data['access_token']);
183
184 $token->setExtraParams($data);
185
186 return $token;
187 }
188
189 /**
190 * Used to configure response type -- we want JSON from github, default is query string format.
191 *
192 * @return array
193 */
194 protected function getExtraOAuthHeaders()
195 {
196 return ['Accept' => 'application/json'];
197 }
198
199 /**
200 * Required for GitHub API calls.
201 *
202 * @return array
203 */
204 protected function getExtraApiHeaders()
205 {
206 return ['Accept' => 'application/vnd.github.v3+json'];
207 }
208
209 /**
210 * {@inheritdoc}
211 */
212 protected function getScopesDelimiter()
213 {
214 return ',';
215 }
216 }
217