From d426e709d575137f6ec4608ef21020aa64a6635e Mon Sep 17 00:00:00 2001 From: Dan Garner Date: Thu, 15 Oct 2015 16:22:43 +0100 Subject: [PATCH] Updated oauth2-client dependency, added a file.php example --- composer.json | 2 +- composer.lock | 353 +++++++++++++++++++++++++++++++----------- example/file.php | 57 +++++++ example/simple.php | 4 +- src/Provider/Xibo.php | 24 ++- 5 files changed, 340 insertions(+), 100 deletions(-) create mode 100644 example/file.php diff --git a/composer.json b/composer.json index 19538d5..f598e82 100644 --- a/composer.json +++ b/composer.json @@ -24,7 +24,7 @@ ], "require": { "php": ">=5.4.0", - "league/oauth2-client": "~0.7" + "league/oauth2-client": "~1" }, "autoload": { "psr-4": { "Xibo\\OAuth2\\Client\\" : "src/" } diff --git a/composer.lock b/composer.lock index c15ac2c..6392ba6 100644 --- a/composer.lock +++ b/composer.lock @@ -4,74 +4,45 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "hash": "edd3b81fbcf68b52abab8ed32364a4cd", - "content-hash": "735bada2d17134d2c487894c2c335d45", + "hash": "4212ea756425513c854408ea54e9e687", + "content-hash": "0a16b3546dc24b48e0080b124aadb25d", "packages": [ { - "name": "guzzle/guzzle", - "version": "v3.9.3", + "name": "guzzlehttp/guzzle", + "version": "6.1.0", "source": { "type": "git", - "url": "https://github.com/guzzle/guzzle3.git", - "reference": "0645b70d953bc1c067bbc8d5bc53194706b628d9" + "url": "https://github.com/guzzle/guzzle.git", + "reference": "66fd14b4d0b8f2389eaf37c5458608c7cb793a81" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/guzzle/guzzle3/zipball/0645b70d953bc1c067bbc8d5bc53194706b628d9", - "reference": "0645b70d953bc1c067bbc8d5bc53194706b628d9", + "url": "https://api.github.com/repos/guzzle/guzzle/zipball/66fd14b4d0b8f2389eaf37c5458608c7cb793a81", + "reference": "66fd14b4d0b8f2389eaf37c5458608c7cb793a81", "shasum": "" }, "require": { - "ext-curl": "*", - "php": ">=5.3.3", - "symfony/event-dispatcher": "~2.1" - }, - "replace": { - "guzzle/batch": "self.version", - "guzzle/cache": "self.version", - "guzzle/common": "self.version", - "guzzle/http": "self.version", - "guzzle/inflection": "self.version", - "guzzle/iterator": "self.version", - "guzzle/log": "self.version", - "guzzle/parser": "self.version", - "guzzle/plugin": "self.version", - "guzzle/plugin-async": "self.version", - "guzzle/plugin-backoff": "self.version", - "guzzle/plugin-cache": "self.version", - "guzzle/plugin-cookie": "self.version", - "guzzle/plugin-curlauth": "self.version", - "guzzle/plugin-error-response": "self.version", - "guzzle/plugin-history": "self.version", - "guzzle/plugin-log": "self.version", - "guzzle/plugin-md5": "self.version", - "guzzle/plugin-mock": "self.version", - "guzzle/plugin-oauth": "self.version", - "guzzle/service": "self.version", - "guzzle/stream": "self.version" + "guzzlehttp/promises": "~1.0", + "guzzlehttp/psr7": "~1.1", + "php": ">=5.5.0" }, "require-dev": { - "doctrine/cache": "~1.3", - "monolog/monolog": "~1.0", - "phpunit/phpunit": "3.7.*", - "psr/log": "~1.0", - "symfony/class-loader": "~2.1", - "zendframework/zend-cache": "2.*,<2.3", - "zendframework/zend-log": "2.*,<2.3" - }, - "suggest": { - "guzzlehttp/guzzle": "Guzzle 5 has moved to a new package name. The package you have installed, Guzzle 3, is deprecated." + "ext-curl": "*", + "phpunit/phpunit": "~4.0", + "psr/log": "~1.0" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "3.9-dev" + "dev-master": "6.1-dev" } }, "autoload": { - "psr-0": { - "Guzzle": "src/", - "Guzzle\\Tests": "tests/" + "files": [ + "src/functions_include.php" + ], + "psr-4": { + "GuzzleHttp\\": "src/" } }, "notification-url": "https://packagist.org/downloads/", @@ -83,13 +54,9 @@ "name": "Michael Dowling", "email": "mtdowling@gmail.com", "homepage": "https://github.com/mtdowling" - }, - { - "name": "Guzzle Community", - "homepage": "https://github.com/guzzle/guzzle/contributors" } ], - "description": "PHP HTTP client. This library is deprecated in favor of https://packagist.org/packages/guzzlehttp/guzzle", + "description": "Guzzle is a PHP HTTP client library", "homepage": "http://guzzlephp.org/", "keywords": [ "client", @@ -100,25 +67,231 @@ "rest", "web service" ], - "time": "2015-03-18 18:23:50" + "time": "2015-09-08 17:36:26" + }, + { + "name": "guzzlehttp/promises", + "version": "1.0.2", + "source": { + "type": "git", + "url": "https://github.com/guzzle/promises.git", + "reference": "97fe7210def29451ec74923b27e552238defd75a" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/guzzle/promises/zipball/97fe7210def29451ec74923b27e552238defd75a", + "reference": "97fe7210def29451ec74923b27e552238defd75a", + "shasum": "" + }, + "require": { + "php": ">=5.5.0" + }, + "require-dev": { + "phpunit/phpunit": "~4.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0-dev" + } + }, + "autoload": { + "psr-4": { + "GuzzleHttp\\Promise\\": "src/" + }, + "files": [ + "src/functions_include.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Michael Dowling", + "email": "mtdowling@gmail.com", + "homepage": "https://github.com/mtdowling" + } + ], + "description": "Guzzle promises library", + "keywords": [ + "promise" + ], + "time": "2015-08-15 19:37:21" + }, + { + "name": "guzzlehttp/psr7", + "version": "1.2.0", + "source": { + "type": "git", + "url": "https://github.com/guzzle/psr7.git", + "reference": "4ef919b0cf3b1989523138b60163bbcb7ba1ff7e" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/guzzle/psr7/zipball/4ef919b0cf3b1989523138b60163bbcb7ba1ff7e", + "reference": "4ef919b0cf3b1989523138b60163bbcb7ba1ff7e", + "shasum": "" + }, + "require": { + "php": ">=5.4.0", + "psr/http-message": "~1.0" + }, + "provide": { + "psr/http-message-implementation": "1.0" + }, + "require-dev": { + "phpunit/phpunit": "~4.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0-dev" + } + }, + "autoload": { + "psr-4": { + "GuzzleHttp\\Psr7\\": "src/" + }, + "files": [ + "src/functions_include.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Michael Dowling", + "email": "mtdowling@gmail.com", + "homepage": "https://github.com/mtdowling" + } + ], + "description": "PSR-7 message implementation", + "keywords": [ + "http", + "message", + "stream", + "uri" + ], + "time": "2015-08-15 19:32:36" + }, + { + "name": "ircmaxell/random-lib", + "version": "v1.1.0", + "source": { + "type": "git", + "url": "https://github.com/ircmaxell/RandomLib.git", + "reference": "13efa4368bb2ac88bb3b1459b487d907de4dbf7c" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/ircmaxell/RandomLib/zipball/13efa4368bb2ac88bb3b1459b487d907de4dbf7c", + "reference": "13efa4368bb2ac88bb3b1459b487d907de4dbf7c", + "shasum": "" + }, + "require": { + "ircmaxell/security-lib": "1.0.*@dev", + "php": ">=5.3.2" + }, + "require-dev": { + "mikey179/vfsstream": "1.1.*", + "phpunit/phpunit": "3.7.*" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-0": { + "RandomLib": "lib" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Anthony Ferrara", + "email": "ircmaxell@ircmaxell.com", + "homepage": "http://blog.ircmaxell.com" + } + ], + "description": "A Library For Generating Secure Random Numbers", + "homepage": "https://github.com/ircmaxell/RandomLib", + "keywords": [ + "cryptography", + "random", + "random-numbers", + "random-strings" + ], + "time": "2015-01-15 16:31:45" + }, + { + "name": "ircmaxell/security-lib", + "version": "1.0.0", + "source": { + "type": "git", + "url": "https://github.com/ircmaxell/SecurityLib.git", + "reference": "80934de3c482dcafb46b5756e59ebece082b6dc7" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/ircmaxell/SecurityLib/zipball/80934de3c482dcafb46b5756e59ebece082b6dc7", + "reference": "80934de3c482dcafb46b5756e59ebece082b6dc7", + "shasum": "" + }, + "require": { + "php": ">=5.3.2" + }, + "require-dev": { + "mikey179/vfsstream": "1.1.*" + }, + "type": "library", + "autoload": { + "psr-0": { + "SecurityLib": "lib" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Anthony Ferrara", + "email": "ircmaxell@ircmaxell.com", + "homepage": "http://blog.ircmaxell.com" + } + ], + "description": "A Base Security Library", + "homepage": "https://github.com/ircmaxell/PHP-SecurityLib", + "time": "2013-04-30 18:00:34" }, { "name": "league/oauth2-client", - "version": "0.12.1", + "version": "1.0.2", "source": { "type": "git", "url": "https://github.com/thephpleague/oauth2-client.git", - "reference": "670ec6e743f5c95441263440afcdabc3fc720547" + "reference": "32d94d0ffc846b7f0fd9a115a7b0795a47a2d11c" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/thephpleague/oauth2-client/zipball/670ec6e743f5c95441263440afcdabc3fc720547", - "reference": "670ec6e743f5c95441263440afcdabc3fc720547", + "url": "https://api.github.com/repos/thephpleague/oauth2-client/zipball/32d94d0ffc846b7f0fd9a115a7b0795a47a2d11c", + "reference": "32d94d0ffc846b7f0fd9a115a7b0795a47a2d11c", "shasum": "" }, "require": { - "guzzle/guzzle": "~3.7", - "php": ">=5.4.0" + "ext-curl": "*", + "guzzlehttp/guzzle": "~6.0", + "ircmaxell/random-lib": "~1.1", + "php": ">=5.5.0" }, "require-dev": { "jakub-onderka/php-parallel-lint": "0.8.*", @@ -128,6 +301,11 @@ "squizlabs/php_codesniffer": "~2.0" }, "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, "autoload": { "psr-4": { "League\\OAuth2\\Client\\": "src/" @@ -156,46 +334,34 @@ "oauth2", "single sign on" ], - "time": "2015-06-20 16:06:31" + "time": "2015-09-22 18:26:19" }, { - "name": "symfony/event-dispatcher", - "version": "v2.7.4", + "name": "psr/http-message", + "version": "1.0", "source": { "type": "git", - "url": "https://github.com/symfony/EventDispatcher.git", - "reference": "b58c916f1db03a611b72dd702564f30ad8fe83fa" + "url": "https://github.com/php-fig/http-message.git", + "reference": "85d63699f0dbedb190bbd4b0d2b9dc707ea4c298" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/EventDispatcher/zipball/b58c916f1db03a611b72dd702564f30ad8fe83fa", - "reference": "b58c916f1db03a611b72dd702564f30ad8fe83fa", + "url": "https://api.github.com/repos/php-fig/http-message/zipball/85d63699f0dbedb190bbd4b0d2b9dc707ea4c298", + "reference": "85d63699f0dbedb190bbd4b0d2b9dc707ea4c298", "shasum": "" }, "require": { - "php": ">=5.3.9" - }, - "require-dev": { - "psr/log": "~1.0", - "symfony/config": "~2.0,>=2.0.5", - "symfony/dependency-injection": "~2.6", - "symfony/expression-language": "~2.6", - "symfony/phpunit-bridge": "~2.7", - "symfony/stopwatch": "~2.3" - }, - "suggest": { - "symfony/dependency-injection": "", - "symfony/http-kernel": "" + "php": ">=5.3.0" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "2.7-dev" + "dev-master": "1.0.x-dev" } }, "autoload": { "psr-4": { - "Symfony\\Component\\EventDispatcher\\": "" + "Psr\\Http\\Message\\": "src/" } }, "notification-url": "https://packagist.org/downloads/", @@ -204,17 +370,20 @@ ], "authors": [ { - "name": "Fabien Potencier", - "email": "fabien@symfony.com" - }, - { - "name": "Symfony Community", - "homepage": "https://symfony.com/contributors" + "name": "PHP-FIG", + "homepage": "http://www.php-fig.org/" } ], - "description": "Symfony EventDispatcher Component", - "homepage": "https://symfony.com", - "time": "2015-08-24 07:13:45" + "description": "Common interface for HTTP messages", + "keywords": [ + "http", + "http-message", + "psr", + "psr-7", + "request", + "response" + ], + "time": "2015-05-04 20:22:00" } ], "packages-dev": [], diff --git a/example/file.php b/example/file.php new file mode 100644 index 0000000..5f790cb --- /dev/null +++ b/example/file.php @@ -0,0 +1,57 @@ + 'p8kh8tq2mknOqMFx7qcgl7FGtFGDlDAlDOxb6TP1', // The client ID assigned to you by the provider + 'clientSecret' => 'KjHPCQHm0ztqA4bcqP1dszYpLpcZqyAvaFlGbFZsq6HUn15ND8d8bZZhpFiPHWqMOQx5sXsAPgdtahICgtdhgFxxOAtlv59kl1GZZLe6dRNvOYQLQyXP9NtxfQkHgHj2wmJwhhhBwqvyPnp9pn13eevMCbDnqfyZJzMkUoG3fofxQPq6Kl9Mh5DtFtiEgXs2XE7zhKfGPOLWH1pUZxn3FLixOehSRUyuUB7SLDqnulPxlFMbV6L4EN4pAG5cRN', // The client password assigned to you by the provider + 'redirectUri' => '', + 'baseUrl' => 'http://192.168.0.28' +]); + +if (!isset($argv[1])) { + $token = $provider->getAccessToken('client_credentials')->getToken(); + echo 'Token for next time: ' . $token; +} +else + $token = $argv[1]; + +try { + // Prepare a file upload + $guzzle = $provider->getHttpClient(); + $response = $guzzle->request('POST', 'http://192.168.0.28/api/library', [ + 'headers' => [ + 'Authorization' => 'Bearer ' . $token + ], + 'multipart' => [ + [ + 'name' => 'name', + 'contents' => 'API upload 2' + ], + [ + 'name' => 'files', + 'contents' => fopen('files/h264.mp4', 'r') + ] + ] + ]); + + + // Get both + echo 'Body: ' . $response->getBody() . PHP_EOL; +} +catch (\GuzzleHttp\Exception\RequestException $e) { + echo 'Client Exception: ' . $e->getMessage() . PHP_EOL; + + if ($e->hasResponse()) { + echo $e->getResponse()->getBody() . PHP_EOL; + } +} \ No newline at end of file diff --git a/example/simple.php b/example/simple.php index f526005..747c1bf 100644 --- a/example/simple.php +++ b/example/simple.php @@ -23,7 +23,7 @@ // Get the URL $authUrl = $provider->getAuthorizationUrl(); - $_SESSION['oauth2state'] = $provider->state; + $_SESSION['oauth2state'] = $provider->getState(); // Go to the auth URL header('Location: ' . $authUrl); @@ -44,7 +44,7 @@ echo json_encode($token); // Get me :) - $me = $provider->getUserDetails($token); + $me = $provider->getResourceOwner($token); echo json_encode($me); } \ No newline at end of file diff --git a/src/Provider/Xibo.php b/src/Provider/Xibo.php index 3292c6a..d1f9f31 100644 --- a/src/Provider/Xibo.php +++ b/src/Provider/Xibo.php @@ -9,6 +9,7 @@ use League\OAuth2\Client\Provider\AbstractProvider; use League\OAuth2\Client\Token\AccessToken; +use Psr\Http\Message\ResponseInterface; class Xibo extends AbstractProvider { @@ -24,7 +25,7 @@ public function setCmsUrl($url) * * @return string */ - public function urlAuthorize() + public function getBaseAuthorizationUrl() { return $this->baseUrl . '/api/authorize'; } @@ -34,7 +35,7 @@ public function urlAuthorize() * * @return string */ - public function urlAccessToken() + public function getBaseAccessTokenUrl(array $params) { return $this->baseUrl . '/api/authorize/access_token'; } @@ -50,7 +51,7 @@ public function urlAccessToken() * @param AccessToken $token * @return string */ - public function urlUserDetails(AccessToken $token) + public function getResourceOwnerDetailsUrl(AccessToken $token) { return $this->baseUrl . '/api/user/me?access_token=' . $token; } @@ -59,12 +60,25 @@ public function urlUserDetails(AccessToken $token) * Given an object response from the server, process the user details into a format expected by the user * of the client. * - * @param object $response + * @param array $response * @param AccessToken $token * @return mixed */ - public function userDetails($response, AccessToken $token) + public function createResourceOwner(array $response, AccessToken $token) { return $response; } + + public function getDefaultScopes() + { + return []; + } + + protected function checkResponse(ResponseInterface $response, $data) + { + if (!empty($data['error'])) { + $message = $data['error']['type'].': '.$data['error']['message']; + throw new IdentityProviderException($message, $data['error']['code'], $data); + } + } } \ No newline at end of file