Skip to content

Commit 04ba628

Browse files
authored
allows string tokens in revoke method (#993)
1 parent 42fc696 commit 04ba628

File tree

2 files changed

+18
-24
lines changed

2 files changed

+18
-24
lines changed

src/Google/AccessToken/Revoke.php

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,18 +45,20 @@ public function __construct(ClientInterface $http = null)
4545
* Revoke an OAuth2 access token or refresh token. This method will revoke the current access
4646
* token, if a token isn't provided.
4747
*
48-
* @param string|null $token The token (access token or a refresh token) that should be revoked.
48+
* @param string|array $token The token (access token or a refresh token) that should be revoked.
4949
* @return boolean Returns True if the revocation was successful, otherwise False.
5050
*/
51-
public function revokeToken(array $token)
51+
public function revokeToken($token)
5252
{
53-
if (isset($token['refresh_token'])) {
54-
$tokenString = $token['refresh_token'];
55-
} else {
56-
$tokenString = $token['access_token'];
53+
if (is_array($token)) {
54+
if (isset($token['refresh_token'])) {
55+
$token = $token['refresh_token'];
56+
} else {
57+
$token = $token['access_token'];
58+
}
5759
}
5860

59-
$body = Psr7\stream_for(http_build_query(array('token' => $tokenString)));
61+
$body = Psr7\stream_for(http_build_query(array('token' => $token)));
6062
$request = new Request(
6163
'POST',
6264
Google_Client::OAUTH2_REVOKE_URI,

tests/Google/AccessToken/RevokeTest.php

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@ public function testRevokeAccess()
3030
$token = '';
3131

3232
$response = $this->getMock('Psr\Http\Message\ResponseInterface');
33-
$response->expects($this->exactly(2))
33+
$response->expects($this->exactly(3))
3434
->method('getStatusCode')
3535
->will($this->returnValue(200));
3636
$http = $this->getMock('GuzzleHttp\ClientInterface');
37-
$http->expects($this->exactly(2))
37+
$http->expects($this->exactly(3))
3838
->method('send')
3939
->will($this->returnCallback(
4040
function ($request) use (&$token, $response) {
@@ -49,13 +49,13 @@ function ($request) use (&$token, $response) {
4949
if ($this->isGuzzle5()) {
5050
$requestToken = null;
5151
$request = $this->getMock('GuzzleHttp\Message\RequestInterface');
52-
$request->expects($this->exactly(2))
52+
$request->expects($this->exactly(3))
5353
->method('getBody')
5454
->will($this->returnCallback(
5555
function () use (&$requestToken) {
5656
return 'token='.$requestToken;
5757
}));
58-
$http->expects($this->exactly(2))
58+
$http->expects($this->exactly(3))
5959
->method('createRequest')
6060
->will($this->returnCallback(
6161
function ($method, $url, $params) use (&$requestToken, $request) {
@@ -88,19 +88,11 @@ function ($method, $url, $params) use (&$requestToken, $request) {
8888
);
8989
$this->assertTrue($revoke->revokeToken($t));
9090
$this->assertEquals($refreshToken, $token);
91-
}
9291

93-
public function testInvalidStringToken()
94-
{
95-
$phpVersion = phpversion();
96-
if ('7' === $phpVersion[0]) {
97-
// primitive type hints actually throw exceptions in PHP7
98-
$this->setExpectedException('TypeError');
99-
} else {
100-
$this->setExpectedException('PHPUnit_Framework_Error');
101-
}
102-
// Test with string token
103-
$revoke = new Google_AccessToken_Revoke();
104-
$revoke->revokeToken('ACCESS_TOKEN');
92+
// Test with token string.
93+
$revoke = new Google_AccessToken_Revoke($http);
94+
$t = $accessToken;
95+
$this->assertTrue($revoke->revokeToken($t));
96+
$this->assertEquals($accessToken, $token);
10597
}
10698
}

0 commit comments

Comments
 (0)