From f15f26894ddb4ff5ff783ba7a7860ea08c828df7 Mon Sep 17 00:00:00 2001 From: Brent Shaffer Date: Fri, 23 Oct 2015 15:32:15 -0700 Subject: [PATCH] updates from master + alpha testers --- .gitignore | 1 + README.md | 3 +- composer.json | 4 +- composer.lock | 1649 ----------------------- examples/index.php | 13 +- src/Google/AccessToken/Verify.php | 12 +- src/Google/Cache/File.php | 3 +- src/Google/Client.php | 117 +- src/Google/Http/MediaFileUpload.php | 77 +- src/Google/Http/REST.php | 11 +- src/Google/Service/Resource.php | 5 +- tests/Google/AccessToken/VerifyTest.php | 8 +- tests/Google/ClientTest.php | 56 + tests/Google/Service/ResourceTest.php | 1 - 14 files changed, 217 insertions(+), 1743 deletions(-) delete mode 100644 composer.lock diff --git a/.gitignore b/.gitignore index 92128bc2d..0a70c65d2 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ .DS_Store phpunit.xml +composer.lock vendor examples/testfile-small.txt examples/testfile.txt diff --git a/README.md b/README.md index fb30e7ee6..610be9f12 100644 --- a/README.md +++ b/README.md @@ -23,8 +23,7 @@ See the examples/ directory for examples of the key client features. You can view them in your browser by running the php built-in web server. ``` -$ cd examples/ -$ php -S localhost:8000 +$ php -S localhost:8000 -t examples/ ``` And then browsing to the host and port you specified diff --git a/composer.json b/composer.json index 752e04780..a2031f8c8 100644 --- a/composer.json +++ b/composer.json @@ -7,7 +7,7 @@ "license": "Apache-2.0", "require": { "php": ">=5.4", - "google/auth": "v0.2-alpha", + "google/auth": "v0.3", "monolog/monolog": "^1.17", "phpseclib/phpseclib": "~2.0", "guzzlehttp/guzzle": "5.2.*" @@ -28,7 +28,7 @@ }, "extra": { "branch-alias": { - "dev-master": "1.1.x-dev" + "dev-master": "2.x-dev" } } } diff --git a/composer.lock b/composer.lock deleted file mode 100644 index db10d558c..000000000 --- a/composer.lock +++ /dev/null @@ -1,1649 +0,0 @@ -{ - "_readme": [ - "This file locks the dependencies of your project to a known state", - "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", - "This file is @generated automatically" - ], - "hash": "6ea1c309fe27e654f278f887bb13198d", - "packages": [ - { - "name": "firebase/php-jwt", - "version": "2.0.0", - "target-dir": "Firebase/PHP-JWT", - "source": { - "type": "git", - "url": "https://github.com/firebase/php-jwt.git", - "reference": "ffcfd888ce1e4f2d70cac2dc9b7301038332fe57" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/firebase/php-jwt/zipball/ffcfd888ce1e4f2d70cac2dc9b7301038332fe57", - "reference": "ffcfd888ce1e4f2d70cac2dc9b7301038332fe57", - "shasum": "" - }, - "require": { - "php": ">=5.2.0" - }, - "type": "library", - "autoload": { - "classmap": [ - "Authentication/", - "Exceptions/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Neuman Vong", - "email": "neuman+pear@twilio.com", - "role": "Developer" - }, - { - "name": "Anant Narayanan", - "email": "anant@php.net", - "role": "Developer" - } - ], - "description": "A simple library to encode and decode JSON Web Tokens (JWT) in PHP. Should conform to the current spec.", - "homepage": "https://github.com/firebase/php-jwt", - "time": "2015-04-01 18:46:38" - }, - { - "name": "google/auth", - "version": "v0.2-alpha", - "source": { - "type": "git", - "url": "https://github.com/google/google-auth-library-php.git", - "reference": "5dc5bcb37a7f50c7132c1feb5037f6c45b249477" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/google/google-auth-library-php/zipball/5dc5bcb37a7f50c7132c1feb5037f6c45b249477", - "reference": "5dc5bcb37a7f50c7132c1feb5037f6c45b249477", - "shasum": "" - }, - "require": { - "firebase/php-jwt": "2.0.0", - "guzzlehttp/guzzle": "5.2.*", - "php": ">=5.4" - }, - "require-dev": { - "phplint/phplint": "0.0.1", - "phpunit/phpunit": "3.7.*" - }, - "type": "library", - "autoload": { - "classmap": [ - "src/" - ], - "psr-4": { - "Google\\Auth\\": "src" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "Apache-2.0" - ], - "description": "Google Auth Library for PHP", - "homepage": "http://github.com/google/google-auth-library-php", - "keywords": [ - "Authentication", - "google", - "oauth2" - ], - "time": "2015-10-09 16:50:15" - }, - { - "name": "guzzlehttp/guzzle", - "version": "5.2.0", - "source": { - "type": "git", - "url": "https://github.com/guzzle/guzzle.git", - "reference": "475b29ccd411f2fa8a408e64576418728c032cfa" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/guzzle/guzzle/zipball/475b29ccd411f2fa8a408e64576418728c032cfa", - "reference": "475b29ccd411f2fa8a408e64576418728c032cfa", - "shasum": "" - }, - "require": { - "guzzlehttp/ringphp": "~1.0", - "php": ">=5.4.0" - }, - "require-dev": { - "ext-curl": "*", - "phpunit/phpunit": "~4.0", - "psr/log": "~1.0" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "5.0-dev" - } - }, - "autoload": { - "psr-4": { - "GuzzleHttp\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Michael Dowling", - "email": "mtdowling@gmail.com", - "homepage": "https://github.com/mtdowling" - } - ], - "description": "Guzzle is a PHP HTTP client library and framework for building RESTful web service clients", - "homepage": "http://guzzlephp.org/", - "keywords": [ - "client", - "curl", - "framework", - "http", - "http client", - "rest", - "web service" - ], - "time": "2015-01-28 01:03:29" - }, - { - "name": "guzzlehttp/ringphp", - "version": "1.1.0", - "source": { - "type": "git", - "url": "https://github.com/guzzle/RingPHP.git", - "reference": "dbbb91d7f6c191e5e405e900e3102ac7f261bc0b" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/guzzle/RingPHP/zipball/dbbb91d7f6c191e5e405e900e3102ac7f261bc0b", - "reference": "dbbb91d7f6c191e5e405e900e3102ac7f261bc0b", - "shasum": "" - }, - "require": { - "guzzlehttp/streams": "~3.0", - "php": ">=5.4.0", - "react/promise": "~2.0" - }, - "require-dev": { - "ext-curl": "*", - "phpunit/phpunit": "~4.0" - }, - "suggest": { - "ext-curl": "Guzzle will use specific adapters if cURL is present" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.1-dev" - } - }, - "autoload": { - "psr-4": { - "GuzzleHttp\\Ring\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Michael Dowling", - "email": "mtdowling@gmail.com", - "homepage": "https://github.com/mtdowling" - } - ], - "description": "Provides a simple API and specification that abstracts away the details of HTTP into a single PHP function.", - "time": "2015-05-20 03:37:09" - }, - { - "name": "guzzlehttp/streams", - "version": "3.0.0", - "source": { - "type": "git", - "url": "https://github.com/guzzle/streams.git", - "reference": "47aaa48e27dae43d39fc1cea0ccf0d84ac1a2ba5" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/guzzle/streams/zipball/47aaa48e27dae43d39fc1cea0ccf0d84ac1a2ba5", - "reference": "47aaa48e27dae43d39fc1cea0ccf0d84ac1a2ba5", - "shasum": "" - }, - "require": { - "php": ">=5.4.0" - }, - "require-dev": { - "phpunit/phpunit": "~4.0" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "3.0-dev" - } - }, - "autoload": { - "psr-4": { - "GuzzleHttp\\Stream\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Michael Dowling", - "email": "mtdowling@gmail.com", - "homepage": "https://github.com/mtdowling" - } - ], - "description": "Provides a simple abstraction over streams of data", - "homepage": "http://guzzlephp.org/", - "keywords": [ - "Guzzle", - "stream" - ], - "time": "2014-10-12 19:18:40" - }, - { - "name": "monolog/monolog", - "version": "1.17.1", - "source": { - "type": "git", - "url": "https://github.com/Seldaek/monolog.git", - "reference": "0524c87587ab85bc4c2d6f5b41253ccb930a5422" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/Seldaek/monolog/zipball/0524c87587ab85bc4c2d6f5b41253ccb930a5422", - "reference": "0524c87587ab85bc4c2d6f5b41253ccb930a5422", - "shasum": "" - }, - "require": { - "php": ">=5.3.0", - "psr/log": "~1.0" - }, - "provide": { - "psr/log-implementation": "1.0.0" - }, - "require-dev": { - "aws/aws-sdk-php": "^2.4.9", - "doctrine/couchdb": "~1.0@dev", - "graylog2/gelf-php": "~1.0", - "php-console/php-console": "^3.1.3", - "phpunit/phpunit": "~4.5", - "phpunit/phpunit-mock-objects": "2.3.0", - "raven/raven": "~0.11", - "ruflin/elastica": ">=0.90 <3.0", - "swiftmailer/swiftmailer": "~5.3", - "videlalvaro/php-amqplib": "~2.4" - }, - "suggest": { - "aws/aws-sdk-php": "Allow sending log messages to AWS services like DynamoDB", - "doctrine/couchdb": "Allow sending log messages to a CouchDB server", - "ext-amqp": "Allow sending log messages to an AMQP server (1.0+ required)", - "ext-mongo": "Allow sending log messages to a MongoDB server", - "graylog2/gelf-php": "Allow sending log messages to a GrayLog2 server", - "php-console/php-console": "Allow sending log messages to Google Chrome", - "raven/raven": "Allow sending log messages to a Sentry server", - "rollbar/rollbar": "Allow sending log messages to Rollbar", - "ruflin/elastica": "Allow sending log messages to an Elastic Search server", - "videlalvaro/php-amqplib": "Allow sending log messages to an AMQP server using php-amqplib" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.16.x-dev" - } - }, - "autoload": { - "psr-4": { - "Monolog\\": "src/Monolog" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Jordi Boggiano", - "email": "j.boggiano@seld.be", - "homepage": "http://seld.be" - } - ], - "description": "Sends your logs to files, sockets, inboxes, databases and various web services", - "homepage": "http://github.com/Seldaek/monolog", - "keywords": [ - "log", - "logging", - "psr-3" - ], - "time": "2015-08-31 09:17:37" - }, - { - "name": "phpseclib/phpseclib", - "version": "2.0.0", - "source": { - "type": "git", - "url": "https://github.com/phpseclib/phpseclib.git", - "reference": "a74aa9efbe61430fcb60157c8e025a48ec8ff604" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/phpseclib/phpseclib/zipball/a74aa9efbe61430fcb60157c8e025a48ec8ff604", - "reference": "a74aa9efbe61430fcb60157c8e025a48ec8ff604", - "shasum": "" - }, - "require": { - "php": ">=5.3.3" - }, - "require-dev": { - "phing/phing": "~2.7", - "phpunit/phpunit": "~4.0", - "sami/sami": "~2.0", - "squizlabs/php_codesniffer": "~2.0" - }, - "suggest": { - "ext-gmp": "Install the GMP (GNU Multiple Precision) extension in order to speed up arbitrary precision integer arithmetic operations.", - "ext-libsodium": "SSH2/SFTP can make use of some algorithms provided by the libsodium-php extension.", - "ext-mcrypt": "Install the Mcrypt extension in order to speed up a few other cryptographic operations.", - "ext-openssl": "Install the OpenSSL extension in order to speed up a wide variety of cryptographic operations.", - "pear-pear/PHP_Compat": "Install PHP_Compat to get phpseclib working on PHP < 5.0.0." - }, - "type": "library", - "autoload": { - "psr-4": { - "phpseclib\\": "phpseclib/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "include-path": [ - "phpseclib/" - ], - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Jim Wigginton", - "email": "terrafrost@php.net", - "role": "Lead Developer" - }, - { - "name": "Patrick Monnerat", - "email": "pm@datasphere.ch", - "role": "Developer" - }, - { - "name": "Andreas Fischer", - "email": "bantu@phpbb.com", - "role": "Developer" - }, - { - "name": "Hans-Jürgen Petrich", - "email": "petrich@tronic-media.com", - "role": "Developer" - } - ], - "description": "PHP Secure Communications Library - Pure-PHP implementations of RSA, AES, SSH2, SFTP, X.509 etc.", - "homepage": "http://phpseclib.sourceforge.net", - "keywords": [ - "BigInteger", - "aes", - "asn.1", - "asn1", - "blowfish", - "crypto", - "cryptography", - "encryption", - "rsa", - "security", - "sftp", - "signature", - "signing", - "ssh", - "twofish", - "x.509", - "x509" - ], - "time": "2015-08-04 04:48:03" - }, - { - "name": "psr/log", - "version": "1.0.0", - "source": { - "type": "git", - "url": "https://github.com/php-fig/log.git", - "reference": "fe0936ee26643249e916849d48e3a51d5f5e278b" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/php-fig/log/zipball/fe0936ee26643249e916849d48e3a51d5f5e278b", - "reference": "fe0936ee26643249e916849d48e3a51d5f5e278b", - "shasum": "" - }, - "type": "library", - "autoload": { - "psr-0": { - "Psr\\Log\\": "" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "PHP-FIG", - "homepage": "http://www.php-fig.org/" - } - ], - "description": "Common interface for logging libraries", - "keywords": [ - "log", - "psr", - "psr-3" - ], - "time": "2012-12-21 11:40:51" - }, - { - "name": "react/promise", - "version": "v2.2.1", - "source": { - "type": "git", - "url": "https://github.com/reactphp/promise.git", - "reference": "3b6fca09c7d56321057fa8867c8dbe1abf648627" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/reactphp/promise/zipball/3b6fca09c7d56321057fa8867c8dbe1abf648627", - "reference": "3b6fca09c7d56321057fa8867c8dbe1abf648627", - "shasum": "" - }, - "require": { - "php": ">=5.4.0" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "2.0-dev" - } - }, - "autoload": { - "psr-4": { - "React\\Promise\\": "src/" - }, - "files": [ - "src/functions_include.php" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Jan Sorgalla", - "email": "jsorgalla@gmail.com" - } - ], - "description": "A lightweight implementation of CommonJS Promises/A for PHP", - "time": "2015-07-03 13:48:55" - } - ], - "packages-dev": [ - { - "name": "doctrine/instantiator", - "version": "1.0.5", - "source": { - "type": "git", - "url": "https://github.com/doctrine/instantiator.git", - "reference": "8e884e78f9f0eb1329e445619e04456e64d8051d" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/doctrine/instantiator/zipball/8e884e78f9f0eb1329e445619e04456e64d8051d", - "reference": "8e884e78f9f0eb1329e445619e04456e64d8051d", - "shasum": "" - }, - "require": { - "php": ">=5.3,<8.0-DEV" - }, - "require-dev": { - "athletic/athletic": "~0.1.8", - "ext-pdo": "*", - "ext-phar": "*", - "phpunit/phpunit": "~4.0", - "squizlabs/php_codesniffer": "~2.0" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.0.x-dev" - } - }, - "autoload": { - "psr-4": { - "Doctrine\\Instantiator\\": "src/Doctrine/Instantiator/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Marco Pivetta", - "email": "ocramius@gmail.com", - "homepage": "http://ocramius.github.com/" - } - ], - "description": "A small, lightweight utility to instantiate objects in PHP without invoking their constructors", - "homepage": "https://github.com/doctrine/instantiator", - "keywords": [ - "constructor", - "instantiate" - ], - "time": "2015-06-14 21:17:01" - }, - { - "name": "phpdocumentor/reflection-docblock", - "version": "2.0.4", - "source": { - "type": "git", - "url": "https://github.com/phpDocumentor/ReflectionDocBlock.git", - "reference": "d68dbdc53dc358a816f00b300704702b2eaff7b8" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/phpDocumentor/ReflectionDocBlock/zipball/d68dbdc53dc358a816f00b300704702b2eaff7b8", - "reference": "d68dbdc53dc358a816f00b300704702b2eaff7b8", - "shasum": "" - }, - "require": { - "php": ">=5.3.3" - }, - "require-dev": { - "phpunit/phpunit": "~4.0" - }, - "suggest": { - "dflydev/markdown": "~1.0", - "erusev/parsedown": "~1.0" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "2.0.x-dev" - } - }, - "autoload": { - "psr-0": { - "phpDocumentor": [ - "src/" - ] - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Mike van Riel", - "email": "mike.vanriel@naenius.com" - } - ], - "time": "2015-02-03 12:10:50" - }, - { - "name": "phpspec/prophecy", - "version": "v1.5.0", - "source": { - "type": "git", - "url": "https://github.com/phpspec/prophecy.git", - "reference": "4745ded9307786b730d7a60df5cb5a6c43cf95f7" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/phpspec/prophecy/zipball/4745ded9307786b730d7a60df5cb5a6c43cf95f7", - "reference": "4745ded9307786b730d7a60df5cb5a6c43cf95f7", - "shasum": "" - }, - "require": { - "doctrine/instantiator": "^1.0.2", - "phpdocumentor/reflection-docblock": "~2.0", - "sebastian/comparator": "~1.1" - }, - "require-dev": { - "phpspec/phpspec": "~2.0" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.4.x-dev" - } - }, - "autoload": { - "psr-0": { - "Prophecy\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Konstantin Kudryashov", - "email": "ever.zet@gmail.com", - "homepage": "http://everzet.com" - }, - { - "name": "Marcello Duarte", - "email": "marcello.duarte@gmail.com" - } - ], - "description": "Highly opinionated mocking framework for PHP 5.3+", - "homepage": "https://github.com/phpspec/prophecy", - "keywords": [ - "Double", - "Dummy", - "fake", - "mock", - "spy", - "stub" - ], - "time": "2015-08-13 10:07:40" - }, - { - "name": "phpunit/php-code-coverage", - "version": "2.2.4", - "source": { - "type": "git", - "url": "https://github.com/sebastianbergmann/php-code-coverage.git", - "reference": "eabf68b476ac7d0f73793aada060f1c1a9bf8979" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/eabf68b476ac7d0f73793aada060f1c1a9bf8979", - "reference": "eabf68b476ac7d0f73793aada060f1c1a9bf8979", - "shasum": "" - }, - "require": { - "php": ">=5.3.3", - "phpunit/php-file-iterator": "~1.3", - "phpunit/php-text-template": "~1.2", - "phpunit/php-token-stream": "~1.3", - "sebastian/environment": "^1.3.2", - "sebastian/version": "~1.0" - }, - "require-dev": { - "ext-xdebug": ">=2.1.4", - "phpunit/phpunit": "~4" - }, - "suggest": { - "ext-dom": "*", - "ext-xdebug": ">=2.2.1", - "ext-xmlwriter": "*" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "2.2.x-dev" - } - }, - "autoload": { - "classmap": [ - "src/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Sebastian Bergmann", - "email": "sb@sebastian-bergmann.de", - "role": "lead" - } - ], - "description": "Library that provides collection, processing, and rendering functionality for PHP code coverage information.", - "homepage": "https://github.com/sebastianbergmann/php-code-coverage", - "keywords": [ - "coverage", - "testing", - "xunit" - ], - "time": "2015-10-06 15:47:00" - }, - { - "name": "phpunit/php-file-iterator", - "version": "1.4.1", - "source": { - "type": "git", - "url": "https://github.com/sebastianbergmann/php-file-iterator.git", - "reference": "6150bf2c35d3fc379e50c7602b75caceaa39dbf0" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-file-iterator/zipball/6150bf2c35d3fc379e50c7602b75caceaa39dbf0", - "reference": "6150bf2c35d3fc379e50c7602b75caceaa39dbf0", - "shasum": "" - }, - "require": { - "php": ">=5.3.3" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.4.x-dev" - } - }, - "autoload": { - "classmap": [ - "src/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Sebastian Bergmann", - "email": "sb@sebastian-bergmann.de", - "role": "lead" - } - ], - "description": "FilterIterator implementation that filters files based on a list of suffixes.", - "homepage": "https://github.com/sebastianbergmann/php-file-iterator/", - "keywords": [ - "filesystem", - "iterator" - ], - "time": "2015-06-21 13:08:43" - }, - { - "name": "phpunit/php-text-template", - "version": "1.2.1", - "source": { - "type": "git", - "url": "https://github.com/sebastianbergmann/php-text-template.git", - "reference": "31f8b717e51d9a2afca6c9f046f5d69fc27c8686" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-text-template/zipball/31f8b717e51d9a2afca6c9f046f5d69fc27c8686", - "reference": "31f8b717e51d9a2afca6c9f046f5d69fc27c8686", - "shasum": "" - }, - "require": { - "php": ">=5.3.3" - }, - "type": "library", - "autoload": { - "classmap": [ - "src/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Sebastian Bergmann", - "email": "sebastian@phpunit.de", - "role": "lead" - } - ], - "description": "Simple template engine.", - "homepage": "https://github.com/sebastianbergmann/php-text-template/", - "keywords": [ - "template" - ], - "time": "2015-06-21 13:50:34" - }, - { - "name": "phpunit/php-timer", - "version": "1.0.7", - "source": { - "type": "git", - "url": "https://github.com/sebastianbergmann/php-timer.git", - "reference": "3e82f4e9fc92665fafd9157568e4dcb01d014e5b" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-timer/zipball/3e82f4e9fc92665fafd9157568e4dcb01d014e5b", - "reference": "3e82f4e9fc92665fafd9157568e4dcb01d014e5b", - "shasum": "" - }, - "require": { - "php": ">=5.3.3" - }, - "type": "library", - "autoload": { - "classmap": [ - "src/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Sebastian Bergmann", - "email": "sb@sebastian-bergmann.de", - "role": "lead" - } - ], - "description": "Utility class for timing", - "homepage": "https://github.com/sebastianbergmann/php-timer/", - "keywords": [ - "timer" - ], - "time": "2015-06-21 08:01:12" - }, - { - "name": "phpunit/php-token-stream", - "version": "1.4.8", - "source": { - "type": "git", - "url": "https://github.com/sebastianbergmann/php-token-stream.git", - "reference": "3144ae21711fb6cac0b1ab4cbe63b75ce3d4e8da" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-token-stream/zipball/3144ae21711fb6cac0b1ab4cbe63b75ce3d4e8da", - "reference": "3144ae21711fb6cac0b1ab4cbe63b75ce3d4e8da", - "shasum": "" - }, - "require": { - "ext-tokenizer": "*", - "php": ">=5.3.3" - }, - "require-dev": { - "phpunit/phpunit": "~4.2" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.4-dev" - } - }, - "autoload": { - "classmap": [ - "src/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Sebastian Bergmann", - "email": "sebastian@phpunit.de" - } - ], - "description": "Wrapper around PHP's tokenizer extension.", - "homepage": "https://github.com/sebastianbergmann/php-token-stream/", - "keywords": [ - "tokenizer" - ], - "time": "2015-09-15 10:49:45" - }, - { - "name": "phpunit/phpunit", - "version": "4.8.12", - "source": { - "type": "git", - "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "00194eb95989190a73198390ceca081ad3441a7f" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/00194eb95989190a73198390ceca081ad3441a7f", - "reference": "00194eb95989190a73198390ceca081ad3441a7f", - "shasum": "" - }, - "require": { - "ext-dom": "*", - "ext-json": "*", - "ext-pcre": "*", - "ext-reflection": "*", - "ext-spl": "*", - "php": ">=5.3.3", - "phpspec/prophecy": "^1.3.1", - "phpunit/php-code-coverage": "~2.1", - "phpunit/php-file-iterator": "~1.4", - "phpunit/php-text-template": "~1.2", - "phpunit/php-timer": ">=1.0.6", - "phpunit/phpunit-mock-objects": "~2.3", - "sebastian/comparator": "~1.1", - "sebastian/diff": "~1.2", - "sebastian/environment": "~1.3", - "sebastian/exporter": "~1.2", - "sebastian/global-state": "~1.0", - "sebastian/version": "~1.0", - "symfony/yaml": "~2.1|~3.0" - }, - "suggest": { - "phpunit/php-invoker": "~1.1" - }, - "bin": [ - "phpunit" - ], - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "4.8.x-dev" - } - }, - "autoload": { - "classmap": [ - "src/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Sebastian Bergmann", - "email": "sebastian@phpunit.de", - "role": "lead" - } - ], - "description": "The PHP Unit Testing framework.", - "homepage": "https://phpunit.de/", - "keywords": [ - "phpunit", - "testing", - "xunit" - ], - "time": "2015-10-12 03:36:47" - }, - { - "name": "phpunit/phpunit-mock-objects", - "version": "2.3.8", - "source": { - "type": "git", - "url": "https://github.com/sebastianbergmann/phpunit-mock-objects.git", - "reference": "ac8e7a3db35738d56ee9a76e78a4e03d97628983" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit-mock-objects/zipball/ac8e7a3db35738d56ee9a76e78a4e03d97628983", - "reference": "ac8e7a3db35738d56ee9a76e78a4e03d97628983", - "shasum": "" - }, - "require": { - "doctrine/instantiator": "^1.0.2", - "php": ">=5.3.3", - "phpunit/php-text-template": "~1.2", - "sebastian/exporter": "~1.2" - }, - "require-dev": { - "phpunit/phpunit": "~4.4" - }, - "suggest": { - "ext-soap": "*" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "2.3.x-dev" - } - }, - "autoload": { - "classmap": [ - "src/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Sebastian Bergmann", - "email": "sb@sebastian-bergmann.de", - "role": "lead" - } - ], - "description": "Mock Object library for PHPUnit", - "homepage": "https://github.com/sebastianbergmann/phpunit-mock-objects/", - "keywords": [ - "mock", - "xunit" - ], - "time": "2015-10-02 06:51:40" - }, - { - "name": "sebastian/comparator", - "version": "1.2.0", - "source": { - "type": "git", - "url": "https://github.com/sebastianbergmann/comparator.git", - "reference": "937efb279bd37a375bcadf584dec0726f84dbf22" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/comparator/zipball/937efb279bd37a375bcadf584dec0726f84dbf22", - "reference": "937efb279bd37a375bcadf584dec0726f84dbf22", - "shasum": "" - }, - "require": { - "php": ">=5.3.3", - "sebastian/diff": "~1.2", - "sebastian/exporter": "~1.2" - }, - "require-dev": { - "phpunit/phpunit": "~4.4" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.2.x-dev" - } - }, - "autoload": { - "classmap": [ - "src/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Jeff Welch", - "email": "whatthejeff@gmail.com" - }, - { - "name": "Volker Dusch", - "email": "github@wallbash.com" - }, - { - "name": "Bernhard Schussek", - "email": "bschussek@2bepublished.at" - }, - { - "name": "Sebastian Bergmann", - "email": "sebastian@phpunit.de" - } - ], - "description": "Provides the functionality to compare PHP values for equality", - "homepage": "http://www.github.com/sebastianbergmann/comparator", - "keywords": [ - "comparator", - "compare", - "equality" - ], - "time": "2015-07-26 15:48:44" - }, - { - "name": "sebastian/diff", - "version": "1.3.0", - "source": { - "type": "git", - "url": "https://github.com/sebastianbergmann/diff.git", - "reference": "863df9687835c62aa423a22412d26fa2ebde3fd3" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/diff/zipball/863df9687835c62aa423a22412d26fa2ebde3fd3", - "reference": "863df9687835c62aa423a22412d26fa2ebde3fd3", - "shasum": "" - }, - "require": { - "php": ">=5.3.3" - }, - "require-dev": { - "phpunit/phpunit": "~4.2" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.3-dev" - } - }, - "autoload": { - "classmap": [ - "src/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Kore Nordmann", - "email": "mail@kore-nordmann.de" - }, - { - "name": "Sebastian Bergmann", - "email": "sebastian@phpunit.de" - } - ], - "description": "Diff implementation", - "homepage": "http://www.github.com/sebastianbergmann/diff", - "keywords": [ - "diff" - ], - "time": "2015-02-22 15:13:53" - }, - { - "name": "sebastian/environment", - "version": "1.3.2", - "source": { - "type": "git", - "url": "https://github.com/sebastianbergmann/environment.git", - "reference": "6324c907ce7a52478eeeaede764f48733ef5ae44" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/environment/zipball/6324c907ce7a52478eeeaede764f48733ef5ae44", - "reference": "6324c907ce7a52478eeeaede764f48733ef5ae44", - "shasum": "" - }, - "require": { - "php": ">=5.3.3" - }, - "require-dev": { - "phpunit/phpunit": "~4.4" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.3.x-dev" - } - }, - "autoload": { - "classmap": [ - "src/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Sebastian Bergmann", - "email": "sebastian@phpunit.de" - } - ], - "description": "Provides functionality to handle HHVM/PHP environments", - "homepage": "http://www.github.com/sebastianbergmann/environment", - "keywords": [ - "Xdebug", - "environment", - "hhvm" - ], - "time": "2015-08-03 06:14:51" - }, - { - "name": "sebastian/exporter", - "version": "1.2.1", - "source": { - "type": "git", - "url": "https://github.com/sebastianbergmann/exporter.git", - "reference": "7ae5513327cb536431847bcc0c10edba2701064e" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/exporter/zipball/7ae5513327cb536431847bcc0c10edba2701064e", - "reference": "7ae5513327cb536431847bcc0c10edba2701064e", - "shasum": "" - }, - "require": { - "php": ">=5.3.3", - "sebastian/recursion-context": "~1.0" - }, - "require-dev": { - "phpunit/phpunit": "~4.4" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.2.x-dev" - } - }, - "autoload": { - "classmap": [ - "src/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Jeff Welch", - "email": "whatthejeff@gmail.com" - }, - { - "name": "Volker Dusch", - "email": "github@wallbash.com" - }, - { - "name": "Bernhard Schussek", - "email": "bschussek@2bepublished.at" - }, - { - "name": "Sebastian Bergmann", - "email": "sebastian@phpunit.de" - }, - { - "name": "Adam Harvey", - "email": "aharvey@php.net" - } - ], - "description": "Provides the functionality to export PHP variables for visualization", - "homepage": "http://www.github.com/sebastianbergmann/exporter", - "keywords": [ - "export", - "exporter" - ], - "time": "2015-06-21 07:55:53" - }, - { - "name": "sebastian/global-state", - "version": "1.1.1", - "source": { - "type": "git", - "url": "https://github.com/sebastianbergmann/global-state.git", - "reference": "bc37d50fea7d017d3d340f230811c9f1d7280af4" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/global-state/zipball/bc37d50fea7d017d3d340f230811c9f1d7280af4", - "reference": "bc37d50fea7d017d3d340f230811c9f1d7280af4", - "shasum": "" - }, - "require": { - "php": ">=5.3.3" - }, - "require-dev": { - "phpunit/phpunit": "~4.2" - }, - "suggest": { - "ext-uopz": "*" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.0-dev" - } - }, - "autoload": { - "classmap": [ - "src/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Sebastian Bergmann", - "email": "sebastian@phpunit.de" - } - ], - "description": "Snapshotting of global state", - "homepage": "http://www.github.com/sebastianbergmann/global-state", - "keywords": [ - "global state" - ], - "time": "2015-10-12 03:26:01" - }, - { - "name": "sebastian/recursion-context", - "version": "1.0.1", - "source": { - "type": "git", - "url": "https://github.com/sebastianbergmann/recursion-context.git", - "reference": "994d4a811bafe801fb06dccbee797863ba2792ba" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/recursion-context/zipball/994d4a811bafe801fb06dccbee797863ba2792ba", - "reference": "994d4a811bafe801fb06dccbee797863ba2792ba", - "shasum": "" - }, - "require": { - "php": ">=5.3.3" - }, - "require-dev": { - "phpunit/phpunit": "~4.4" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.0.x-dev" - } - }, - "autoload": { - "classmap": [ - "src/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Jeff Welch", - "email": "whatthejeff@gmail.com" - }, - { - "name": "Sebastian Bergmann", - "email": "sebastian@phpunit.de" - }, - { - "name": "Adam Harvey", - "email": "aharvey@php.net" - } - ], - "description": "Provides functionality to recursively process PHP variables", - "homepage": "http://www.github.com/sebastianbergmann/recursion-context", - "time": "2015-06-21 08:04:50" - }, - { - "name": "sebastian/version", - "version": "1.0.6", - "source": { - "type": "git", - "url": "https://github.com/sebastianbergmann/version.git", - "reference": "58b3a85e7999757d6ad81c787a1fbf5ff6c628c6" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/version/zipball/58b3a85e7999757d6ad81c787a1fbf5ff6c628c6", - "reference": "58b3a85e7999757d6ad81c787a1fbf5ff6c628c6", - "shasum": "" - }, - "type": "library", - "autoload": { - "classmap": [ - "src/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Sebastian Bergmann", - "email": "sebastian@phpunit.de", - "role": "lead" - } - ], - "description": "Library that helps with managing the version number of Git-hosted PHP projects", - "homepage": "https://github.com/sebastianbergmann/version", - "time": "2015-06-21 13:59:46" - }, - { - "name": "squizlabs/php_codesniffer", - "version": "2.3.4", - "source": { - "type": "git", - "url": "https://github.com/squizlabs/PHP_CodeSniffer.git", - "reference": "11a2545c44a5915f883e2e5ec12e14ed345e3ab2" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/squizlabs/PHP_CodeSniffer/zipball/11a2545c44a5915f883e2e5ec12e14ed345e3ab2", - "reference": "11a2545c44a5915f883e2e5ec12e14ed345e3ab2", - "shasum": "" - }, - "require": { - "ext-tokenizer": "*", - "ext-xmlwriter": "*", - "php": ">=5.1.2" - }, - "bin": [ - "scripts/phpcs", - "scripts/phpcbf" - ], - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "2.0.x-dev" - } - }, - "autoload": { - "classmap": [ - "CodeSniffer.php", - "CodeSniffer/CLI.php", - "CodeSniffer/Exception.php", - "CodeSniffer/File.php", - "CodeSniffer/Fixer.php", - "CodeSniffer/Report.php", - "CodeSniffer/Reporting.php", - "CodeSniffer/Sniff.php", - "CodeSniffer/Tokens.php", - "CodeSniffer/Reports/", - "CodeSniffer/Tokenizers/", - "CodeSniffer/DocGenerators/", - "CodeSniffer/Standards/AbstractPatternSniff.php", - "CodeSniffer/Standards/AbstractScopeSniff.php", - "CodeSniffer/Standards/AbstractVariableSniff.php", - "CodeSniffer/Standards/IncorrectPatternException.php", - "CodeSniffer/Standards/Generic/Sniffs/", - "CodeSniffer/Standards/MySource/Sniffs/", - "CodeSniffer/Standards/PEAR/Sniffs/", - "CodeSniffer/Standards/PSR1/Sniffs/", - "CodeSniffer/Standards/PSR2/Sniffs/", - "CodeSniffer/Standards/Squiz/Sniffs/", - "CodeSniffer/Standards/Zend/Sniffs/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Greg Sherwood", - "role": "lead" - } - ], - "description": "PHP_CodeSniffer tokenizes PHP, JavaScript and CSS files and detects violations of a defined set of coding standards.", - "homepage": "http://www.squizlabs.com/php-codesniffer", - "keywords": [ - "phpcs", - "standards" - ], - "time": "2015-09-09 00:18:50" - }, - { - "name": "symfony/css-selector", - "version": "v2.7.5", - "source": { - "type": "git", - "url": "https://github.com/symfony/css-selector.git", - "reference": "abe19cc0429a06be0c133056d1f9859854860970" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/symfony/css-selector/zipball/abe19cc0429a06be0c133056d1f9859854860970", - "reference": "abe19cc0429a06be0c133056d1f9859854860970", - "shasum": "" - }, - "require": { - "php": ">=5.3.9" - }, - "require-dev": { - "symfony/phpunit-bridge": "~2.7" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "2.7-dev" - } - }, - "autoload": { - "psr-4": { - "Symfony\\Component\\CssSelector\\": "" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Jean-François Simon", - "email": "jeanfrancois.simon@sensiolabs.com" - }, - { - "name": "Fabien Potencier", - "email": "fabien@symfony.com" - }, - { - "name": "Symfony Community", - "homepage": "https://symfony.com/contributors" - } - ], - "description": "Symfony CssSelector Component", - "homepage": "https://symfony.com", - "time": "2015-09-22 13:49:29" - }, - { - "name": "symfony/dom-crawler", - "version": "v2.7.5", - "source": { - "type": "git", - "url": "https://github.com/symfony/dom-crawler.git", - "reference": "2e185ca136399f902b948694987e62c80099c052" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/symfony/dom-crawler/zipball/2e185ca136399f902b948694987e62c80099c052", - "reference": "2e185ca136399f902b948694987e62c80099c052", - "shasum": "" - }, - "require": { - "php": ">=5.3.9" - }, - "require-dev": { - "symfony/css-selector": "~2.3", - "symfony/phpunit-bridge": "~2.7" - }, - "suggest": { - "symfony/css-selector": "" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "2.7-dev" - } - }, - "autoload": { - "psr-4": { - "Symfony\\Component\\DomCrawler\\": "" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Fabien Potencier", - "email": "fabien@symfony.com" - }, - { - "name": "Symfony Community", - "homepage": "https://symfony.com/contributors" - } - ], - "description": "Symfony DomCrawler Component", - "homepage": "https://symfony.com", - "time": "2015-09-20 21:13:58" - }, - { - "name": "symfony/yaml", - "version": "v2.7.5", - "source": { - "type": "git", - "url": "https://github.com/symfony/yaml.git", - "reference": "31cb2ad0155c95b88ee55fe12bc7ff92232c1770" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/symfony/yaml/zipball/31cb2ad0155c95b88ee55fe12bc7ff92232c1770", - "reference": "31cb2ad0155c95b88ee55fe12bc7ff92232c1770", - "shasum": "" - }, - "require": { - "php": ">=5.3.9" - }, - "require-dev": { - "symfony/phpunit-bridge": "~2.7" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "2.7-dev" - } - }, - "autoload": { - "psr-4": { - "Symfony\\Component\\Yaml\\": "" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Fabien Potencier", - "email": "fabien@symfony.com" - }, - { - "name": "Symfony Community", - "homepage": "https://symfony.com/contributors" - } - ], - "description": "Symfony Yaml Component", - "homepage": "https://symfony.com", - "time": "2015-09-14 14:14:09" - } - ], - "aliases": [], - "minimum-stability": "stable", - "stability-flags": { - "google/auth": 15 - }, - "prefer-stable": false, - "prefer-lowest": false, - "platform": { - "php": ">=5.4" - }, - "platform-dev": [] -} diff --git a/examples/index.php b/examples/index.php index e901d4bf2..1949cbf4b 100644 --- a/examples/index.php +++ b/examples/index.php @@ -1,15 +1,16 @@ - - -
-  To view this page on a webserver using PHP 5.4 or above run:
-    php -S localhost:8080
-  
+ To view this example, run the following command from the root directory of this repository: + + php -S localhost:8080 -t examples/ + + And then browse to "localhost:8080" in your web browser + + diff --git a/src/Google/AccessToken/Verify.php b/src/Google/AccessToken/Verify.php index 669e315c4..19dccfe56 100644 --- a/src/Google/AccessToken/Verify.php +++ b/src/Google/AccessToken/Verify.php @@ -29,6 +29,8 @@ class Google_AccessToken_Verify { const FEDERATED_SIGNON_CERT_URL = 'https://www.googleapis.com/oauth2/v3/certs'; + const OAUTH2_ISSUER = 'accounts.google.com'; + const OAUTH2_ISSUER_HTTPS = 'https://accounts.google.com'; /** * @var GuzzleHttp\ClientInterface The http client @@ -84,13 +86,21 @@ public function verifyIdToken($idToken, $audience = null) $rsa->getPublicKey(), array('RS256') ); + if (property_exists($payload, 'aud')) { if ($audience && $payload->aud != $audience) { return false; } } - return $payload; + // support HTTP and HTTPS issuers + // @see https://developers.google.com/identity/sign-in/web/backend-auth + $issuers = array(self::OAUTH2_ISSUER, self::OAUTH2_ISSUER_HTTPS); + if (!isset($payload->iss) || !in_array($payload->iss, $issuers)) { + return false; + } + + return (array) $payload; } catch (ExpiredException $e) { return false; } catch (DomainException $e) { diff --git a/src/Google/Cache/File.php b/src/Google/Cache/File.php index 45b2ef00d..92b09ae9d 100644 --- a/src/Google/Cache/File.php +++ b/src/Google/Cache/File.php @@ -154,7 +154,8 @@ private function getCacheDir($file, $forWrite) $storageDir = $this->path . '/' . substr(md5($file), 0, 2); if ($forWrite && ! is_dir($storageDir)) { if (! mkdir($storageDir, 0700, true)) { - $this->client->getLogger()->error( + $this->log( + 'error', 'File cache creation failed', array('dir' => $storageDir) ); diff --git a/src/Google/Client.php b/src/Google/Client.php index 343242204..c62cd0d0e 100644 --- a/src/Google/Client.php +++ b/src/Google/Client.php @@ -18,8 +18,10 @@ use Google\Auth\ApplicationDefaultCredentials; use Google\Auth\AuthTokenFetcher; use Google\Auth\CacheInterface; +use Google\Auth\CredentialsLoader; use Google\Auth\OAuth2; use Google\Auth\ScopedAccessToken; +use Google\Auth\ServiceAccountCredentials; use Google\Auth\Simple; use Google\Auth\UserRefreshCredentials; use GuzzleHttp\Client; @@ -38,7 +40,7 @@ class Google_Client const LIBVER = "2.0.0-alpha"; const USER_AGENT_SUFFIX = "google-api-php-client/"; const OAUTH2_REVOKE_URI = 'https://accounts.google.com/o/oauth2/revoke'; - const OAUTH2_TOKEN_URI = 'https://www.googleapis.com/oauth2/v3/token'; + const OAUTH2_TOKEN_URI = 'https://www.googleapis.com/oauth2/v4/token'; const OAUTH2_AUTH_URL = 'https://accounts.google.com/o/oauth2/auth'; const API_BASE_PATH = 'https://www.googleapis.com'; @@ -148,8 +150,6 @@ public function getLibraryVersion() */ public function authenticate($code) { - trigger_error('use Google_Client::fetchAccessTokenWithAuthCode', E_DEPRECATED); - return $this->fetchAccessTokenWithAuthCode($code); } @@ -187,8 +187,6 @@ public function fetchAccessTokenWithAuthCode($code) */ public function refreshTokenWithAssertion() { - trigger_error('use Google_Client::fetchAccessTokenWithAssertion', E_DEPRECATED); - return $this->fetchAccessTokenWithAssertion(); } @@ -233,8 +231,6 @@ public function fetchAccessTokenWithAssertion() */ public function refreshToken($refreshToken) { - trigger_error('use Google_Client::fetchAccessTokenWithRefreshToken', E_DEPRECATED); - return $this->fetchAccessTokenWithRefreshToken($refreshToken); } @@ -324,20 +320,45 @@ public function createAuthUrl($scope = null) * set in the Google API Client object * * @param GuzzleHttp\ClientInterface $http the http client object. + * @param GuzzleHttp\ClientInterface $authHttp an http client for authentication. * @return void */ - public function authorize(ClientInterface $http) + public function authorize(ClientInterface $http, ClientInterface $authHttp = null) { $subscriber = null; $authIdentifier = null; + + // if we end up needing to make an HTTP request to retrieve credentials, we + // can use our existing one, but we need to throw exceptions so the error + // bubbles up. + $authHttp = $authHttp ?: $this->createDefaultAuthHttpClient($http); + + // These conditionals represent the decision tree for authentication + // 1. Check for Application Default Credentials + // 2. Check for API Key + // 3a. Check for an Access Token + // 3b. If access token exists but is expired, try to refresh it if ($this->config->get('use_application_default_credentials')) { $scopes = $this->prepareScopes(); - $subscriber = ApplicationDefaultCredentials::getFetcher( - $scopes, - null, - array(), - $this->cache - ); + if ($sub = $this->config->get('subject')) { + // for service account domain-wide authority (impersonating a user) + // @see https://developers.google.com/identity/protocols/OAuth2ServiceAccount + if (!$creds = CredentialsLoader::fromEnv($scopes)) { + $creds = CredentialsLoader::fromWellKnownFile($scopes); + } + if (!$creds instanceof ServiceAccountCredentials) { + throw new DomainException('domain-wide authority requires service account credentials'); + } + $creds->setSub($sub); + $subscriber = new AuthTokenFetcher($creds, array(), $this->cache, $authHttp); + } else { + $subscriber = ApplicationDefaultCredentials::getFetcher( + $scopes, + $authHttp, + array(), + $this->cache + ); + } $authIdentifier = 'google_auth'; } elseif ($key = $this->config->get('developer_key')) { // if a developer key is set, authorize using that @@ -346,20 +367,19 @@ public function authorize(ClientInterface $http) } elseif ($token = $this->getAccessToken()) { $scopes = $this->prepareScopes(); // add refresh subscriber to request a new token - if ($this->isAccessTokenExpired()) { - if (isset($token['refresh_token'])) { - $subscriber = $this->createUserRefreshCredentials( - $scopes, - $token['refresh_token'] - ); - $authIdentifier = 'google_auth'; - } + if ($this->isAccessTokenExpired() && isset($token['refresh_token'])) { + $subscriber = $this->createUserRefreshCredentials( + $scopes, + $token['refresh_token'], + $authHttp + ); + $authIdentifier = 'google_auth'; } else { $subscriber = new ScopedAccessToken( function ($scopes) use ($token) { return $token['access_token']; }, - $scopes, + (array) $scopes, [] ); $authIdentifier = 'scoped'; @@ -431,6 +451,13 @@ public function getAccessToken() return $this->token; } + public function getRefreshToken() + { + if (isset($this->token['refresh_token'])) { + return $this->token['refresh_token']; + } + } + /** * Returns if the access_token is expired. * @return bool Returns True if the access_token is expired. @@ -798,16 +825,14 @@ public function getConfig($name, $default = null) } /** - * Set the auth config from the JSON file in the path - * provided. This should match the file downloaded from - * the "Download JSON" button on in the Google Developer - * Console. - * @param string $file the file location of the client json + * For backwards compatibility + * alias for setAuthConfig + * + * @param string $file the configuration file + * @throws Google_Exception */ public function setAuthConfigFile($file) { - trigger_error('use Google_Client::setAuthConfig', E_USER_DEPRECATED); - $this->setAuthConfig($file); } @@ -842,7 +867,6 @@ public function setAuthConfig($config) $tmpFile = tempnam(sys_get_temp_dir(), 'appcreds'); file_put_contents($tmpFile, json_encode($config)); putenv('GOOGLE_APPLICATION_CREDENTIALS='.$tmpFile); - } elseif (isset($config[$key])) { // old-style $this->setClientId($config[$key]['client_id']); @@ -860,6 +884,16 @@ public function setAuthConfig($config) } } + /** + * Use when the service account has been delegated domain wide access. + * + * @param string subject an email address account to impersonate + */ + public function setSubject($subject) + { + $this->config->set('subject', $subject); + } + /** * Declare whether making API calls should make the call immediately, or * return a request which can be called with ->execute(); @@ -1006,8 +1040,25 @@ protected function createDefaultHttpClient() return new Client($options); } - private function createUserRefreshCredentials($scope, $refreshToken) + protected function createDefaultAuthHttpClient($http = null) { + $options = [ + 'base_url' => $this->config->get('base_path'), + 'defaults' => [ + 'exceptions' => true, + 'verify' => $http ? $http->getDefaultOption('verify') : true, + 'proxy' => $http ? $http->getDefaultOption('proxy') : null, + ] + ]; + + return new Client($options); + } + + private function createUserRefreshCredentials( + $scope, + $refreshToken, + ClientInterface $http = null + ) { $creds = array_filter( array( 'client_id' => $this->getClientId(), @@ -1020,7 +1071,7 @@ private function createUserRefreshCredentials($scope, $refreshToken) new UserRefreshCredentials($scope, $creds), [], $this->getCache(), - clone $this->getHttpClient() + $http ); } } diff --git a/src/Google/Http/MediaFileUpload.php b/src/Google/Http/MediaFileUpload.php index b0d6b9dc4..74b837f89 100644 --- a/src/Google/Http/MediaFileUpload.php +++ b/src/Google/Http/MediaFileUpload.php @@ -109,6 +109,36 @@ public function getProgress() return $this->progress; } + /** + * Send the next part of the file to upload. + * @param [$chunk] the next set of bytes to send. If false will used $data passed + * at construct time. + */ + public function nextChunk($chunk = false) + { + $resumeUri = $this->getResumeUri(); + + if (false == $chunk) { + $chunk = substr($this->data, $this->progress, $this->chunkSize); + } + + $lastBytePos = $this->progress + strlen($chunk) - 1; + $headers = array( + 'content-range' => "bytes $this->progress-$lastBytePos/$this->size", + 'content-length' => strlen($chunk), + 'expect' => '', + ); + + $request = new Request( + 'PUT', + $resumeUri, + $headers, + Stream::factory($chunk) + ); + + return $this->makePutRequest($request); + } + /** * Return the HTTP result code from the last call made. * @return int code @@ -127,14 +157,9 @@ public function getHttpResultCode() * @return false|mixed false when the upload is unfinished or the decoded http response * */ - private function makePutRequest(Google_Http_Request $httpRequest) + private function makePutRequest(Request $request) { - if ($this->client->getClassConfig("Google_Http_Request", "enable_gzip_for_uploads")) { - $http->setDefaultOption('disable_gzip', false); - } else { - $http->setDefaultOption('disable_gzip', true); - } - + $http = $this->client->getHttpClient(); $response = $http->send($request); $this->httpResultCode = $response->getStatusCode(); @@ -163,37 +188,6 @@ private function makePutRequest(Google_Http_Request $httpRequest) return $result; } - /** - * Send the next part of the file to upload. - * @param [$chunk] the next set of bytes to send. If false will used $data passed - * at construct time. - */ - public function nextChunk($chunk = false) - { - if (false == $this->resumeUri) { - $this->resumeUri = $this->fetchResumeUri(); - } - - if (false == $chunk) { - $chunk = substr($this->data, $this->progress, $this->chunkSize); - } - $lastBytePos = $this->progress + strlen($chunk) - 1; - $headers = array( - 'content-range' => "bytes $this->progress-$lastBytePos/$this->size", - 'content-type' => $this->request->getRequestHeader('content-type'), - 'content-length' => $this->chunkSize, - 'expect' => '', - ); - - $httpRequest = new Google_Http_Request( - $this->resumeUri, - 'PUT', - $headers, - $chunk - ); - return $this->makePutRequest($httpRequest); - } - /** * Resume a previously unfinished upload * @param $resumeUri the resume-URI of the unfinished, resumable upload. @@ -210,6 +204,7 @@ public function resume($resumeUri) 'PUT', $headers ); + return $this->makePutRequest($httpRequest); } @@ -288,7 +283,11 @@ public function getUploadType($meta) public function getResumeUri() { - return ( $this->resumeUri !== null ? $this->resumeUri : $this->fetchResumeUri() ); + if (is_null($this->resumeUri)) { + $this->resumeUri = $this->fetchResumeUri(); + } + + return $this->resumeUri; } private function fetchResumeUri() diff --git a/src/Google/Http/REST.php b/src/Google/Http/REST.php index 6bf51fa00..85fe61b82 100644 --- a/src/Google/Http/REST.php +++ b/src/Google/Http/REST.php @@ -18,6 +18,7 @@ use GuzzleHttp\Message\RequestInterface; use GuzzleHttp\Message\ResponseInterface; use GuzzleHttp\ClientInterface; +use GuzzleHttp\Exception\RequestException; /** * This class implements the RESTful transport of apiServiceRequest()'s @@ -65,7 +66,15 @@ public static function execute( */ public static function doExecute(ClientInterface $client, RequestInterface $request) { - $response = $client->send($request); + try { + $response = $client->send($request); + } catch (RequestException $e) { + // if Guzzle throws an exception, catch it and handle the response + if (!$e->hasResponse()) { + throw $e; + } + $response = $e->getResponse(); + } return self::decodeHttpResponse($response, $request); } diff --git a/src/Google/Service/Resource.php b/src/Google/Service/Resource.php index f1e576375..5df9e94b0 100644 --- a/src/Google/Service/Resource.php +++ b/src/Google/Service/Resource.php @@ -110,10 +110,7 @@ public function call($name, $arguments, $expected_class = null) $parameters['postBody'] = $this->convertToArrayAndStripNulls($parameters['postBody']); } - $postBody = json_encode($parameters['postBody']); - if ($postBody === false && $parameters['postBody'] !== false) { - throw new Google_Exception("JSON encoding failed. Ensure all strings in the request are UTF-8 encoded."); - } + $postBody = (array) $parameters['postBody']; unset($parameters['postBody']); } diff --git a/tests/Google/AccessToken/VerifyTest.php b/tests/Google/AccessToken/VerifyTest.php index cae3fb101..db34967a7 100644 --- a/tests/Google/AccessToken/VerifyTest.php +++ b/tests/Google/AccessToken/VerifyTest.php @@ -44,8 +44,8 @@ public function testValidateIdToken() $data = json_decode(JWT::urlSafeB64Decode($segments[1])); $verify = new Google_AccessToken_Verify(); $payload = $verify->verifyIdToken($token['id_token'], $data->aud); - $this->assertTrue(isset($payload->sub)); - $this->assertTrue(strlen($payload->sub) > 0); + $this->assertTrue(isset($payload['sub'])); + $this->assertTrue(strlen($payload['sub']) > 0); // TODO: Need to be smart about testing/disabling the // caching for this test to make sense. Not sure how to do that @@ -54,7 +54,7 @@ public function testValidateIdToken() $data = json_decode(JWT::urlSafeB64Decode($segments[1])); $verify = new Google_AccessToken_Verify(); $payload = $verify->verifyIdToken($token['id_token'], $data->aud); - $this->assertTrue(isset($payload->sub)); - $this->assertTrue(strlen($payload->sub) > 0); + $this->assertTrue(isset($payload['sub'])); + $this->assertTrue(strlen($payload['sub']) > 0); } } diff --git a/tests/Google/ClientTest.php b/tests/Google/ClientTest.php index f38bbdfa8..d335ea24f 100644 --- a/tests/Google/ClientTest.php +++ b/tests/Google/ClientTest.php @@ -283,6 +283,62 @@ public function testNoAuth() $this->assertEquals(0, count($listeners)); } + public function testApplicationDefaultCredentials() + { + $client = new Google_Client(); + $client->setAuthConfig(__DIR__.'/../config/application-default-credentials.json'); + + $http = new Client(); + $client->authorize($http); + + $listeners = $http->getEmitter()->listeners('before'); + + $this->assertEquals(1, count($listeners)); + $this->assertEquals(2, count($listeners[0])); + $this->assertInstanceOf('Google\Auth\AuthTokenFetcher', $listeners[0][0]); + + // access the protected $fetcher property + $class = new ReflectionClass(get_class($listeners[0][0])); + $property = $class->getProperty('fetcher'); + $property->setAccessible(true); + $fetcher = $property->getValue($listeners[0][0]); + + $this->assertInstanceOf('Google\Auth\ServiceAccountCredentials', $fetcher); + } + + public function testApplicationDefaultCredentialsWithSubject() + { + $sub = 'sub123'; + $client = new Google_Client(); + $client->setAuthConfig(__DIR__.'/../config/application-default-credentials.json'); + $client->setSubject($sub); + + $http = new Client(); + $client->authorize($http); + + $listeners = $http->getEmitter()->listeners('before'); + + $this->assertEquals(1, count($listeners)); + $this->assertEquals(2, count($listeners[0])); + $this->assertInstanceOf('Google\Auth\AuthTokenFetcher', $listeners[0][0]); + + // access the protected $fetcher property + $class = new ReflectionClass(get_class($listeners[0][0])); + $property = $class->getProperty('fetcher'); + $property->setAccessible(true); + $fetcher = $property->getValue($listeners[0][0]); + + $this->assertInstanceOf('Google\Auth\ServiceAccountCredentials', $fetcher); + + // access the protected $auth property + $class = new ReflectionClass(get_class($fetcher)); + $property = $class->getProperty('auth'); + $property->setAccessible(true); + $auth = $property->getValue($fetcher); + + $this->assertEquals($sub, $auth->getSub()); + } + /** * Test that the ID token is properly refreshed. */ diff --git a/tests/Google/Service/ResourceTest.php b/tests/Google/Service/ResourceTest.php index dec93aee0..cb002b299 100644 --- a/tests/Google/Service/ResourceTest.php +++ b/tests/Google/Service/ResourceTest.php @@ -193,5 +193,4 @@ public function testAppEngineSslCerts() $this->client->getHttpClient()->getDefaultOption('verify') ); } - }