diff --git a/src/Provider/Google.php b/src/Provider/Google.php index dbd982a..1896885 100644 --- a/src/Provider/Google.php +++ b/src/Provider/Google.php @@ -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; } } diff --git a/test/src/Provider/GoogleTest.php b/test/src/Provider/GoogleTest.php index 235b426..0d12156 100644 --- a/test/src/Provider/GoogleTest.php +++ b/test/src/Provider/GoogleTest.php @@ -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); + } }