1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-10 08:52:39 +01:00

Upgrade to GitHub v3 API

Summary: GitHub dropped support for the v2 API today, which breaks login and registration. Use the v3 API instead.

Test Plan: Registered and logged in with GitHub. Verified process pulled email/photo/name/username correctly.

Reviewers: vrana, btrahan

Reviewed By: vrana

CC: aran

Differential Revision: https://secure.phabricator.com/D2726
This commit is contained in:
epriestley 2012-06-12 12:01:10 -07:00
parent 80de8c93c9
commit 06371bc2cd
2 changed files with 10 additions and 6 deletions

View file

@ -60,9 +60,14 @@ final class PhabricatorOAuthLoginController
$userinfo_uri = new PhutilURI($provider->getUserInfoURI()); $userinfo_uri = new PhutilURI($provider->getUserInfoURI());
$userinfo_uri->setQueryParam('access_token', $this->accessToken); $userinfo_uri->setQueryParam('access_token', $this->accessToken);
$userinfo_uri = (string)$userinfo_uri;
try { try {
$user_data = @file_get_contents($userinfo_uri); $user_data = @file_get_contents($userinfo_uri);
if ($user_data === false) {
throw new PhabricatorOAuthProviderException(
"Request to '{$userinfo_uri}' failed!");
}
$provider->setUserData($user_data); $provider->setUserData($user_data);
} catch (PhabricatorOAuthProviderException $e) { } catch (PhabricatorOAuthProviderException $e) {
return $this->buildErrorResponse(new PhabricatorOAuthFailureView()); return $this->buildErrorResponse(new PhabricatorOAuthFailureView());

View file

@ -71,12 +71,12 @@ final class PhabricatorOAuthProviderGitHub extends PhabricatorOAuthProvider {
public function getTestURIs() { public function getTestURIs() {
return array( return array(
'http://github.com', 'http://api.github.com',
); );
} }
public function getUserInfoURI() { public function getUserInfoURI() {
return 'https://github.com/api/v2/json/user/show'; return 'https://api.github.com/user';
} }
public function getMinimumScope() { public function getMinimumScope() {
@ -84,7 +84,7 @@ final class PhabricatorOAuthProviderGitHub extends PhabricatorOAuthProvider {
} }
public function setUserData($data) { public function setUserData($data) {
$data = idx(json_decode($data, true), 'user'); $data = json_decode($data, true);
$this->validateUserData($data); $this->validateUserData($data);
$this->userData = $data; $this->userData = $data;
return $this; return $this;
@ -103,9 +103,8 @@ final class PhabricatorOAuthProviderGitHub extends PhabricatorOAuthProvider {
} }
public function retrieveUserProfileImage() { public function retrieveUserProfileImage() {
$id = $this->userData['gravatar_id']; $uri = idx($this->userData, 'avatar_url');
if ($id) { if ($uri) {
$uri = 'http://www.gravatar.com/avatar/'.$id.'?s=50';
return @file_get_contents($uri); return @file_get_contents($uri);
} }
return null; return null;