Skip to content

Commit

Permalink
Merge pull request #207 from AnduAanei/Google_access_type
Browse files Browse the repository at this point in the history
Add support for specifying the access_type parameter for Google OAuth
  • Loading branch information
ramsey committed Feb 3, 2015
2 parents 428a28e + 3afc1f9 commit 362b2f9
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/Provider/Google.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,22 @@ public function getHostedDomain()
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';
Expand Down Expand Up @@ -97,6 +113,10 @@ public function getAuthorizationUrl($options = array())
$url .= '&' . $this->httpBuildQuery(['hd' => $this->hostedDomain]);
}

if (!empty($this->accessType)) {
$url .= '&' . $this->httpBuildQuery(['access_type'=> $this->accessType]);
}

return $url;
}
}
13 changes: 13 additions & 0 deletions test/src/Provider/GoogleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ protected function setUp()
'clientSecret' => 'mock_secret',
'redirectUri' => 'none',
'hostedDomain' => 'mock_domain',
'accessType' => 'mock_access_type'
]);
}

Expand All @@ -37,6 +38,7 @@ public function testAuthorizationUrl()
$this->assertArrayHasKey('response_type', $query);
$this->assertArrayHasKey('approval_prompt', $query);
$this->assertArrayHasKey('hd', $query);
$this->assertArrayHasKey('access_type', $query);
$this->assertNotNull($this->provider->state);
}

Expand Down Expand Up @@ -107,4 +109,15 @@ public function testSetHostedDomain()
$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);
}
}

0 comments on commit 362b2f9

Please sign in to comment.