From 65810afe06db548c74d5041f5e96f6da55afa363 Mon Sep 17 00:00:00 2001 From: Sergio Vera Date: Tue, 23 Dec 2014 16:16:50 +0100 Subject: [PATCH 1/2] Added support for Github Enterprise --- src/Provider/Github.php | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/Provider/Github.php b/src/Provider/Github.php index 1ef473c..009c5d8 100644 --- a/src/Provider/Github.php +++ b/src/Provider/Github.php @@ -8,19 +8,24 @@ class Github extends AbstractProvider { public $responseType = 'string'; + public $domain = 'https://github.com'; + public function urlAuthorize() { - return 'https://github.com/login/oauth/authorize'; + return $this->domain.'/login/oauth/authorize'; } public function urlAccessToken() { - return 'https://github.com/login/oauth/access_token'; + return $this->domain.'/login/oauth/access_token'; } public function urlUserDetails(\League\OAuth2\Client\Token\AccessToken $token) { - return 'https://api.github.com/user?access_token='.$token; + if ($this->domain == 'https://github.com') { + return $this->domain.'/user?access_token='.$token; + } + return $this->domain.'/api/v3/user?access_token='.$token; } public function userDetails($response, \League\OAuth2\Client\Token\AccessToken $token) @@ -36,7 +41,7 @@ class Github extends AbstractProvider 'name' => $name, 'email' => $email, 'urls' => [ - 'GitHub' => 'http://github.com/'.$response->login, + 'GitHub' => $this->domain.'/'.$response->login, ], ]); From 3df7382ee184a8e0726953e766446906113f9f7a Mon Sep 17 00:00:00 2001 From: Sergio Vera Date: Tue, 23 Dec 2014 17:25:56 +0100 Subject: [PATCH 2/2] Added tests --- test/src/Provider/GithubTest.php | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/test/src/Provider/GithubTest.php b/test/src/Provider/GithubTest.php index 5db808c..4ca85f9 100644 --- a/test/src/Provider/GithubTest.php +++ b/test/src/Provider/GithubTest.php @@ -114,4 +114,22 @@ class GithubTest extends \PHPUnit_Framework_TestCase $this->assertEquals('mock_name', $user->name); $this->assertEquals('mock_email', $this->provider->getUserEmail($token)); } + + public function testGithubEnterpriseDomainUrls() + { + $this->provider->domain = 'https://github.company.com'; + + $client = m::mock('Guzzle\Service\Client'); + $response = m::mock('Guzzle\Http\Message\Response'); + $response->shouldReceive('getBody')->times(1)->andReturn('access_token=mock_access_token&expires=3600&refresh_token=mock_refresh_token&otherKey={1234}'); + + $client->shouldReceive('setBaseUrl')->times(1); + $client->shouldReceive('post->send')->times(1)->andReturn($response); + $this->provider->setHttpClient($client); + $token = $this->provider->getAccessToken('authorization_code', ['code' => 'mock_authorization_code']); + + $this->assertEquals($this->provider->domain.'/login/oauth/authorize', $this->provider->urlAuthorize()); + $this->assertEquals($this->provider->domain.'/login/oauth/access_token', $this->provider->urlAccessToken()); + $this->assertEquals($this->provider->domain.'/api/v3/user?access_token=mock_access_token', $this->provider->urlUserDetails($token)); + } }