Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for specifying the access_type parameter for Google OAuth #207

Merged
merged 3 commits into from
Feb 3, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}
}