Merge branch 'aripringle-master'

1.0
Ben Ramsey 2014-11-28 14:48:59 -05:00
commit 5b93378c59
2 changed files with 40 additions and 0 deletions

View File

@ -13,6 +13,22 @@ class Google extends AbstractProvider
'https://www.googleapis.com/auth/userinfo.email',
];
/**
* @var string If set, this will be sent to google as the "hd" parameter.
* @link https://developers.google.com/accounts/docs/OAuth2Login#hd-param
*/
public $hostedDomain = '';
public function setHostedDomain($hd)
{
$this->hostedDomain = $hd;
}
public function getHostedDomain()
{
return $this->hostedDomain;
}
public function urlAuthorize()
{
return 'https://accounts.google.com/o/oauth2/auth';
@ -62,4 +78,15 @@ class Google extends AbstractProvider
{
return [$response->given_name, $response->family_name];
}
public function getAuthorizationUrl($options = array())
{
$url = parent::getAuthorizationUrl($options);
if (!empty($this->hostedDomain)) {
$url .= '&' . $this->httpBuildQuery(['hd' => $this->hostedDomain]);
}
return $url;
}
}

View File

@ -14,6 +14,7 @@ class GoogleTest extends \PHPUnit_Framework_TestCase
'clientId' => 'mock_client_id',
'clientSecret' => 'mock_secret',
'redirectUri' => 'none',
'hostedDomain' => 'mock_domain',
]);
}
@ -29,6 +30,7 @@ class GoogleTest extends \PHPUnit_Framework_TestCase
$this->assertArrayHasKey('scope', $query);
$this->assertArrayHasKey('response_type', $query);
$this->assertArrayHasKey('approval_prompt', $query);
$this->assertArrayHasKey('hd', $query);
$this->assertNotNull($this->provider->state);
}
@ -88,4 +90,15 @@ class GoogleTest extends \PHPUnit_Framework_TestCase
$this->assertEquals('mock_email', $this->provider->getUserEmail($token));
$this->assertEquals('mock_email', $user->email);
}
public function testGetHostedDomain()
{
$this->assertEquals('mock_domain', $this->provider->getHostedDomain());
}
public function testSetHostedDomain()
{
$this->provider->setHostedDomain('changed_domain');
$this->assertEquals('changed_domain', $this->provider->hostedDomain);
}
}