Changeset View
Changeset View
Standalone View
Standalone View
src/applications/auth/adapter/PhutilGitHubAuthAdapter.php
| Show First 20 Lines • Show All 45 Lines • ▼ Show 20 Lines | final class PhutilGitHubAuthAdapter extends PhutilOAuthAuthAdapter { | ||||
| } | } | ||||
| protected function getTokenBaseURI() { | protected function getTokenBaseURI() { | ||||
| return 'https://github.com/login/oauth/access_token'; | return 'https://github.com/login/oauth/access_token'; | ||||
| } | } | ||||
| protected function loadOAuthAccountData() { | protected function loadOAuthAccountData() { | ||||
| $uri = new PhutilURI('https://api.github.com/user'); | $uri = new PhutilURI('https://api.github.com/user'); | ||||
| $uri->replaceQueryParam('access_token', $this->getAccessToken()); | |||||
| $future = new HTTPSFuture($uri); | $future = new HTTPSFuture($uri); | ||||
| // NOTE: GitHub requires a User-Agent string. | // NOTE: GitHub requires a User-Agent string. | ||||
| $future->addHeader('User-Agent', __CLASS__); | $future->addHeader('User-Agent', __CLASS__); | ||||
| // See T13485. Circa early 2020, GitHub has deprecated use of the | |||||
| // "access_token" URI parameter. | |||||
| $token_header = sprintf('token %s', $this->getAccessToken()); | |||||
| $future->addHeader('Authorization', $token_header); | |||||
| list($body) = $future->resolvex(); | list($body) = $future->resolvex(); | ||||
| try { | try { | ||||
| return phutil_json_decode($body); | return phutil_json_decode($body); | ||||
| } catch (PhutilJSONParserException $ex) { | } catch (PhutilJSONParserException $ex) { | ||||
| throw new PhutilProxyException( | throw new PhutilProxyException( | ||||
| pht('Expected valid JSON response from GitHub account data request.'), | pht('Expected valid JSON response from GitHub account data request.'), | ||||
| $ex); | $ex); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||