Merge pull request #207 from AnduAanei/Google_access_type

Add support for specifying the access_type parameter for Google OAuth
oauth1test
Ben Ramsey 2015-02-03 09:35:01 -06:00
commit 362b2f9cab
2 changed files with 33 additions and 0 deletions

View File

@ -29,6 +29,22 @@ class Google extends AbstractProvider
return $this->hostedDomain;
}
/**
* @var string If set, this will be sent to google as the "access_type" parameter.
* @link https://developers.google.com/accounts/docs/OAuth2WebServer#offline
*/
public $accessType = '';
public function setAccessType($accessType)
{
$this->accessType = $accessType;
}
public function getAccessType()
{
return $this->accessType;
}
public function urlAuthorize()
{
return 'https://accounts.google.com/o/oauth2/auth';
@ -97,6 +113,10 @@ class Google extends AbstractProvider
$url .= '&' . $this->httpBuildQuery(['hd' => $this->hostedDomain]);
}
if (!empty($this->accessType)) {
$url .= '&' . $this->httpBuildQuery(['access_type'=> $this->accessType]);
}
return $url;
}
}

View File

@ -15,6 +15,7 @@ class GoogleTest extends \PHPUnit_Framework_TestCase
'clientSecret' => 'mock_secret',
'redirectUri' => 'none',
'hostedDomain' => 'mock_domain',
'accessType' => 'mock_access_type'
]);
}
@ -37,6 +38,7 @@ class GoogleTest extends \PHPUnit_Framework_TestCase
$this->assertArrayHasKey('response_type', $query);
$this->assertArrayHasKey('approval_prompt', $query);
$this->assertArrayHasKey('hd', $query);
$this->assertArrayHasKey('access_type', $query);
$this->assertNotNull($this->provider->state);
}
@ -107,4 +109,15 @@ class GoogleTest extends \PHPUnit_Framework_TestCase
$this->provider->setHostedDomain('changed_domain');
$this->assertEquals('changed_domain', $this->provider->hostedDomain);
}
public function testGetAccessType()
{
$this->assertEquals('mock_access_type', $this->provider->getAccessType());
}
public function testSetAccessType()
{
$this->provider->setAccessType('changed_access_type');
$this->assertEquals('changed_access_type', $this->provider->accessType);
}
}