Skip to content

Commit

Permalink
Merge ffef5ea into ae01838
Browse files Browse the repository at this point in the history
  • Loading branch information
rchavik committed Jan 26, 2015
2 parents ae01838 + ffef5ea commit 0674d9a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/Provider/Github.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ class Github extends AbstractProvider

public $domain = 'https://github.com';

public $apiDomain = 'https://api.github.com';

public function urlAuthorize()
{
return $this->domain.'/login/oauth/authorize';
Expand All @@ -23,15 +25,15 @@ public function urlAccessToken()
public function urlUserDetails(\League\OAuth2\Client\Token\AccessToken $token)
{
if ($this->domain === 'https://github.com') {
return $this->domain.'/user?access_token='.$token;
return $this->apiDomain.'/user?access_token='.$token;
}
return $this->domain.'/api/v3/user?access_token='.$token;
}

public function urlUserEmails(\League\OAuth2\Client\Token\AccessToken $token)
{
if ($this->domain === 'https://github.com') {
return $this->domain.'/user/emails?access_token='.$token;
return $this->apiDomain.'/user/emails?access_token='.$token;
}
return $this->domain.'/api/v3/user/emails?access_token='.$token;
}
Expand Down
17 changes: 17 additions & 0 deletions test/src/Provider/GithubTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,23 @@ public function testUserData()
$this->assertEquals('mock_email', $this->provider->getUserEmail($token));
}

public function testGithubDomainUrls()
{
$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->apiDomain.'/user?access_token=mock_access_token', $this->provider->urlUserDetails($token));
$this->assertEquals($this->provider->apiDomain.'/user/emails?access_token=mock_access_token', $this->provider->urlUserEmails($token));
}

public function testGithubEnterpriseDomainUrls()
{
$this->provider->domain = 'https://github.company.com';
Expand Down

0 comments on commit 0674d9a

Please sign in to comment.