Skip to content

Commit

Permalink
Merge pull request #188 from svera/github-enterprise-support
Browse files Browse the repository at this point in the history
Added support for Github Enterprise
  • Loading branch information
ramsey committed Dec 29, 2014
2 parents bebb96f + 3df7382 commit 69cd359
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/Provider/Github.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -36,7 +41,7 @@ public function userDetails($response, \League\OAuth2\Client\Token\AccessToken $
'name' => $name,
'email' => $email,
'urls' => [
'GitHub' => 'http://github.com/'.$response->login,
'GitHub' => $this->domain.'/'.$response->login,
],
]);

Expand Down
18 changes: 18 additions & 0 deletions test/src/Provider/GithubTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,4 +114,22 @@ public function testUserData()
$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));
}
}

0 comments on commit 69cd359

Please sign in to comment.