Merge pull request #188 from svera/github-enterprise-support

Added support for Github Enterprise
oauth1test
Ben Ramsey 2014-12-29 04:56:10 -05:00
commit 69cd359e0f
2 changed files with 27 additions and 4 deletions

View File

@ -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,
],
]);

View File

@ -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));
}
}