Skip to content

Commit 5620e57

Browse files
committed
Merge pull request #768 from google/add-support-for-guzzle-6
Add support for guzzle 6
2 parents 14d7ebf + 6dc8190 commit 5620e57

29 files changed

+1042
-717
lines changed

.travis.yml

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,34 +7,41 @@ env:
77
global:
88
- MEMCACHE_HOST=127.0.0.1
99
- MEMCACHE_PORT=11211
10+
matrix:
11+
- GUZZLE_VERSION=~5.2
12+
- GUZZLE_VERSION=~6.0
1013

1114
sudo: false
1215

1316
cache:
1417
directories:
1518
- $HOME/.composer/cache
1619

20+
php:
21+
- 5.4
22+
- 5.5
23+
- 5.6
24+
- 7.0
25+
- hhvm
26+
27+
# Guzzle 6.0 is not compatible with PHP 5.4
1728
matrix:
18-
fast_finish: true
19-
include:
29+
exclude:
2030
- php: 5.4
21-
- php: 5.5
22-
- php: 5.6
23-
env: PHPCS=true
24-
- php: hhvm
31+
env: GUZZLE_VERSION=~6.0
2532

2633
before_install:
2734
- composer self-update
2835

2936
install:
3037
- composer install
38+
- composer require guzzlehttp/guzzle:$GUZZLE_VERSION
3139

3240
before_script:
33-
- sh -c 'if [ "$TRAVIS_PHP_VERSION" != "hhvm" ]; then echo "extension=memcache.so" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini; fi;'
34-
- sh -c 'if [ "$TRAVIS_PHP_VERSION" != "hhvm" ]; then echo "extension=memcached.so" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini; fi;'
3541
- phpenv version-name | grep ^5.[34] && echo "extension=apc.so" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini ; true
3642
- phpenv version-name | grep ^5.[34] && echo "apc.enable_cli=1" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini ; true
3743

3844
script:
3945
- vendor/bin/phpunit
40-
- if [[ "$PHPCS" == "true" ]]; then vendor/bin/phpcs src --standard=style/ruleset.xml -np; fi
46+
- if [[ "$TRAVIS_PHP_VERSION" == "5.4" ]]; then vendor/bin/phpcs src --standard=style/ruleset.xml -np; fi
47+

composer.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,13 @@
77
"license": "Apache-2.0",
88
"require": {
99
"php": ">=5.4",
10-
"google/auth": "0.4",
10+
"google/auth": "0.5",
1111
"firebase/php-jwt": "~2.0|~3.0",
1212
"monolog/monolog": "^1.17",
1313
"phpseclib/phpseclib": "~2.0",
14-
"guzzlehttp/guzzle": "5.2.*"
14+
"guzzlehttp/guzzle": "~5.2|~6.0",
15+
"guzzlehttp/psr7": "1.2.*",
16+
"psr/http-message": "1.0.*"
1517
},
1618
"require-dev": {
1719
"phpunit/phpunit": "~4",

examples/idtoken.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@
2424
* Ensure you've downloaded your oauth credentials
2525
************************************************/
2626
if (!$oauth_credentials = getOAuthCredentialsFile()) {
27-
echo missingOAuth2CredentialsWarning();
28-
exit;
27+
return missingOAuth2CredentialsWarning();
2928
}
3029

3130
/************************************************

examples/large-file-upload.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@
2424
* Ensure you've downloaded your oauth credentials
2525
************************************************/
2626
if (!$oauth_credentials = getOAuthCredentialsFile()) {
27-
echo missingOAuth2CredentialsWarning();
28-
exit;
27+
return missingOAuth2CredentialsWarning();
2928
}
3029

3130
/************************************************

examples/multi-api.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@
2525
* Ensure you've downloaded your oauth credentials
2626
************************************************/
2727
if (!$oauth_credentials = getOAuthCredentialsFile()) {
28-
echo missingOAuth2CredentialsWarning();
29-
exit;
28+
return missingOAuth2CredentialsWarning();
3029
}
3130

3231
/************************************************

examples/simple-file-upload.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@
2424
* Ensure you've downloaded your oauth credentials
2525
************************************************/
2626
if (!$oauth_credentials = getOAuthCredentialsFile()) {
27-
echo missingOAuth2CredentialsWarning();
28-
exit;
27+
return missingOAuth2CredentialsWarning();
2928
}
3029

3130
/************************************************

examples/url-shortener.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@
2424
* Ensure you've downloaded your oauth credentials
2525
************************************************/
2626
if (!$oauth_credentials = getOAuthCredentialsFile()) {
27-
echo missingOAuth2CredentialsWarning();
28-
exit;
27+
return missingOAuth2CredentialsWarning();
2928
}
3029

3130
/************************************************

src/Google/AccessToken/Revoke.php

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,10 @@
1616
* limitations under the License.
1717
*/
1818

19-
use GuzzleHttp\Client;
19+
use Google\Auth\HttpHandler\HttpHandlerFactory;
2020
use GuzzleHttp\ClientInterface;
21+
use GuzzleHttp\Psr7;
22+
use GuzzleHttp\Psr7\Request;
2123

2224
/**
2325
* Wrapper around Google Access Tokens which provides convenience functions
@@ -36,10 +38,6 @@ class Google_AccessToken_Revoke
3638
*/
3739
public function __construct(ClientInterface $http = null)
3840
{
39-
if (is_null($http)) {
40-
$http = new Client();
41-
}
42-
4341
$this->http = $http;
4442
}
4543

@@ -53,17 +51,25 @@ public function __construct(ClientInterface $http = null)
5351
public function revokeToken(array $token)
5452
{
5553
if (isset($token['refresh_token'])) {
56-
$tokenString = $token['refresh_token'];
54+
$tokenString = $token['refresh_token'];
5755
} else {
58-
$tokenString = $token['access_token'];
56+
$tokenString = $token['access_token'];
5957
}
6058

61-
$request = $this->http->createRequest('POST', Google_Client::OAUTH2_REVOKE_URI);
62-
$request->addHeader('Cache-Control', 'no-store');
63-
$request->addHeader('Content-Type', 'application/x-www-form-urlencoded');
64-
$request->getBody()->replaceFields(array('token' => $tokenString));
59+
$body = Psr7\stream_for(http_build_query(array('token' => $tokenString)));
60+
$request = new Request(
61+
'POST',
62+
Google_Client::OAUTH2_REVOKE_URI,
63+
[
64+
'Cache-Control' => 'no-store',
65+
'Content-Type' => 'application/x-www-form-urlencoded',
66+
],
67+
$body
68+
);
69+
70+
$httpHandler = HttpHandlerFactory::build($this->http);
6571

66-
$response = $this->http->send($request);
72+
$response = $httpHandler($request);
6773
if ($response->getStatusCode() == 200) {
6874
return true;
6975
}

src/Google/AccessToken/Verify.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public function verifyIdToken($idToken, $audience = null)
7373
}
7474

7575
// Check signature
76-
$certs = $this->getFederatedSignonCerts();
76+
$certs = $this->getFederatedSignOnCerts();
7777
foreach ($certs as $cert) {
7878
$modulus = new BigInteger($this->jwt->urlsafeB64Decode($cert['n']), 256);
7979
$exponent = new BigInteger($this->jwt->urlsafeB64Decode($cert['e']), 256);
@@ -152,7 +152,7 @@ private function retrieveCertsFromLocation($url)
152152
$response = $this->http->get($url);
153153

154154
if ($response->getStatusCode() == 200) {
155-
return $response->json();
155+
return json_decode((string) $response->getBody(), true);
156156
}
157157
throw new Google_Exception(
158158
sprintf(
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
/**
3+
* Copyright 2015 Google Inc. All Rights Reserved.
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
use GuzzleHttp\Client;
19+
use GuzzleHttp\ClientInterface;
20+
21+
class Google_AuthHandler_AuthHandlerFactory
22+
{
23+
/**
24+
* Builds out a default http handler for the installed version of guzzle.
25+
*
26+
* @return Google_AuthHandler_Guzzle5AuthHandler|Google_AuthHandler_Guzzle6AuthHandler
27+
* @throws Exception
28+
*/
29+
public static function build($cache = null)
30+
{
31+
$version = ClientInterface::VERSION;
32+
33+
switch ($version[0]) {
34+
case '5':
35+
return new Google_AuthHandler_Guzzle5AuthHandler($cache);
36+
case '6':
37+
return new Google_AuthHandler_Guzzle6AuthHandler($cache);
38+
default:
39+
throw new Exception('Version not supported');
40+
}
41+
}
42+
}

0 commit comments

Comments
 (0)