コード例 #1
0
 public function testInvalidStringToken()
 {
     $phpVersion = phpversion();
     if ('7' === $phpVersion[0]) {
         // primitive type hints actually throw exceptions in PHP7
         $this->setExpectedException('TypeError');
     } else {
         $this->setExpectedException('PHPUnit_Framework_Error');
     }
     // Test with string token
     $revoke = new Google_AccessToken_Revoke();
     $revoke->revokeToken('ACCESS_TOKEN');
 }
コード例 #2
0
 public function testRevokeAccess()
 {
     $accessToken = 'ACCESS_TOKEN';
     $refreshToken = 'REFRESH_TOKEN';
     $token = '';
     $response = $this->getMock('Psr\\Http\\Message\\ResponseInterface');
     $response->expects($this->exactly(3))->method('getStatusCode')->will($this->returnValue(200));
     $http = $this->getMock('GuzzleHttp\\ClientInterface');
     $http->expects($this->exactly(3))->method('send')->will($this->returnCallback(function ($request) use(&$token, $response) {
         parse_str((string) $request->getBody(), $fields);
         $token = isset($fields['token']) ? $fields['token'] : null;
         return $response;
     }));
     // adds support for extra "createRequest" step (required for Guzzle 5)
     if ($this->isGuzzle5()) {
         $requestToken = null;
         $request = $this->getMock('GuzzleHttp\\Message\\RequestInterface');
         $request->expects($this->exactly(3))->method('getBody')->will($this->returnCallback(function () use(&$requestToken) {
             return 'token=' . $requestToken;
         }));
         $http->expects($this->exactly(3))->method('createRequest')->will($this->returnCallback(function ($method, $url, $params) use(&$requestToken, $request) {
             parse_str((string) $params['body'], $fields);
             $requestToken = isset($fields['token']) ? $fields['token'] : null;
             return $request;
         }));
     }
     $t = array('access_token' => $accessToken, 'created' => time(), 'expires_in' => '3600');
     // Test with access token.
     $revoke = new Google_AccessToken_Revoke($http);
     $this->assertTrue($revoke->revokeToken($t));
     $this->assertEquals($accessToken, $token);
     // Test with refresh token.
     $revoke = new Google_AccessToken_Revoke($http);
     $t = array('access_token' => $accessToken, 'refresh_token' => $refreshToken, 'created' => time(), 'expires_in' => '3600');
     $this->assertTrue($revoke->revokeToken($t));
     $this->assertEquals($refreshToken, $token);
     // Test with token string.
     $revoke = new Google_AccessToken_Revoke($http);
     $t = $accessToken;
     $this->assertTrue($revoke->revokeToken($t));
     $this->assertEquals($accessToken, $token);
 }
コード例 #3
0
ファイル: Client.php プロジェクト: branJakJak/dienSiSystem
 /**
  * Revoke an OAuth2 access token or refresh token. This method will revoke the current access
  * token, if a token isn't provided.
  *
  * @param string|null $token The token (access token or a refresh token) that should be revoked.
  * @return boolean Returns True if the revocation was successful, otherwise False.
  */
 public function revokeToken($token = null)
 {
     $tokenRevoker = new Google_AccessToken_Revoke($this->getHttpClient());
     return $tokenRevoker->revokeToken($token ?: $this->getAccessToken());
 }
コード例 #4
0
 /** @expectedException PHPUnit_Framework_Error */
 public function testInvalidStringToken()
 {
     // Test with string token
     $revoke = new Google_AccessToken_Revoke();
     $revoke->revokeToken('ACCESS_TOKEN');
 }