Updated examples

This commit is contained in:
Alex Bilbie 2017-07-01 16:30:36 +01:00
parent 1954120c3d
commit 107cfc3678
8 changed files with 158 additions and 37 deletions

View File

@ -5,8 +5,9 @@
"require-dev": { "require-dev": {
"league/event": "^2.1", "league/event": "^2.1",
"lcobucci/jwt": "^3.1", "lcobucci/jwt": "^3.1",
"paragonie/random_compat": "^1.1", "paragonie/random_compat": "^2.0",
"psr/http-message": "^1.0" "psr/http-message": "^1.0",
"defuse/php-encryption": "^2.1"
}, },
"autoload": { "autoload": {
"psr-4": { "psr-4": {

178
examples/composer.lock generated
View File

@ -4,23 +4,25 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"hash": "48bcb7a3514d7c7f271c554ba1440124", "content-hash": "9813ed7c3b6dcf107f44df9392935b8f",
"content-hash": "e41be75973527cb9d63f27ad14ac8624",
"packages": [ "packages": [
{ {
"name": "container-interop/container-interop", "name": "container-interop/container-interop",
"version": "1.1.0", "version": "1.2.0",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/container-interop/container-interop.git", "url": "https://github.com/container-interop/container-interop.git",
"reference": "fc08354828f8fd3245f77a66b9e23a6bca48297e" "reference": "79cbf1341c22ec75643d841642dd5d6acd83bdb8"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/container-interop/container-interop/zipball/fc08354828f8fd3245f77a66b9e23a6bca48297e", "url": "https://api.github.com/repos/container-interop/container-interop/zipball/79cbf1341c22ec75643d841642dd5d6acd83bdb8",
"reference": "fc08354828f8fd3245f77a66b9e23a6bca48297e", "reference": "79cbf1341c22ec75643d841642dd5d6acd83bdb8",
"shasum": "" "shasum": ""
}, },
"require": {
"psr/container": "^1.0"
},
"type": "library", "type": "library",
"autoload": { "autoload": {
"psr-4": { "psr-4": {
@ -32,7 +34,8 @@
"MIT" "MIT"
], ],
"description": "Promoting the interoperability of container objects (DIC, SL, etc.)", "description": "Promoting the interoperability of container objects (DIC, SL, etc.)",
"time": "2014-12-30 15:22:37" "homepage": "https://github.com/container-interop/container-interop",
"time": "2017-02-14T19:40:03+00:00"
}, },
{ {
"name": "nikic/fast-route", "name": "nikic/fast-route",
@ -75,7 +78,7 @@
"router", "router",
"routing" "routing"
], ],
"time": "2015-06-18 19:15:47" "time": "2015-06-18T19:15:47+00:00"
}, },
{ {
"name": "pimple/pimple", "name": "pimple/pimple",
@ -121,20 +124,69 @@
"container", "container",
"dependency injection" "dependency injection"
], ],
"time": "2015-09-11 15:10:35" "time": "2015-09-11T15:10:35+00:00"
}, },
{ {
"name": "psr/http-message", "name": "psr/container",
"version": "1.0", "version": "1.0.0",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/php-fig/http-message.git", "url": "https://github.com/php-fig/container.git",
"reference": "85d63699f0dbedb190bbd4b0d2b9dc707ea4c298" "reference": "b7ce3b176482dbbc1245ebf52b181af44c2cf55f"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/php-fig/http-message/zipball/85d63699f0dbedb190bbd4b0d2b9dc707ea4c298", "url": "https://api.github.com/repos/php-fig/container/zipball/b7ce3b176482dbbc1245ebf52b181af44c2cf55f",
"reference": "85d63699f0dbedb190bbd4b0d2b9dc707ea4c298", "reference": "b7ce3b176482dbbc1245ebf52b181af44c2cf55f",
"shasum": ""
},
"require": {
"php": ">=5.3.0"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.0.x-dev"
}
},
"autoload": {
"psr-4": {
"Psr\\Container\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "PHP-FIG",
"homepage": "http://www.php-fig.org/"
}
],
"description": "Common Container Interface (PHP FIG PSR-11)",
"homepage": "https://github.com/php-fig/container",
"keywords": [
"PSR-11",
"container",
"container-interface",
"container-interop",
"psr"
],
"time": "2017-02-14T16:28:37+00:00"
},
{
"name": "psr/http-message",
"version": "1.0.1",
"source": {
"type": "git",
"url": "https://github.com/php-fig/http-message.git",
"reference": "f6561bf28d520154e4b0ec72be95418abe6d9363"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/php-fig/http-message/zipball/f6561bf28d520154e4b0ec72be95418abe6d9363",
"reference": "f6561bf28d520154e4b0ec72be95418abe6d9363",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -162,6 +214,7 @@
} }
], ],
"description": "Common interface for HTTP messages", "description": "Common interface for HTTP messages",
"homepage": "https://github.com/php-fig/http-message",
"keywords": [ "keywords": [
"http", "http",
"http-message", "http-message",
@ -170,7 +223,7 @@
"request", "request",
"response" "response"
], ],
"time": "2015-05-04 20:22:00" "time": "2016-08-06T14:39:51+00:00"
}, },
{ {
"name": "slim/slim", "name": "slim/slim",
@ -236,22 +289,85 @@
"micro", "micro",
"router" "router"
], ],
"time": "2015-12-07 14:11:09" "time": "2015-12-07T14:11:09+00:00"
} }
], ],
"packages-dev": [ "packages-dev": [
{ {
"name": "lcobucci/jwt", "name": "defuse/php-encryption",
"version": "3.1.1", "version": "v2.1.0",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/lcobucci/jwt.git", "url": "https://github.com/defuse/php-encryption.git",
"reference": "afea8e682e911a21574fd8519321b32522fa25b5" "reference": "5176f5abb38d3ea8a6e3ac6cd3bbb54d8185a689"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/lcobucci/jwt/zipball/afea8e682e911a21574fd8519321b32522fa25b5", "url": "https://api.github.com/repos/defuse/php-encryption/zipball/5176f5abb38d3ea8a6e3ac6cd3bbb54d8185a689",
"reference": "afea8e682e911a21574fd8519321b32522fa25b5", "reference": "5176f5abb38d3ea8a6e3ac6cd3bbb54d8185a689",
"shasum": ""
},
"require": {
"ext-openssl": "*",
"paragonie/random_compat": "~2.0",
"php": ">=5.4.0"
},
"require-dev": {
"nikic/php-parser": "^2.0|^3.0",
"phpunit/phpunit": "^4|^5"
},
"bin": [
"bin/generate-defuse-key"
],
"type": "library",
"autoload": {
"psr-4": {
"Defuse\\Crypto\\": "src"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Taylor Hornby",
"email": "taylor@defuse.ca",
"homepage": "https://defuse.ca/"
},
{
"name": "Scott Arciszewski",
"email": "info@paragonie.com",
"homepage": "https://paragonie.com"
}
],
"description": "Secure PHP Encryption Library",
"keywords": [
"aes",
"authenticated encryption",
"cipher",
"crypto",
"cryptography",
"encrypt",
"encryption",
"openssl",
"security",
"symmetric key cryptography"
],
"time": "2017-05-18T21:28:48+00:00"
},
{
"name": "lcobucci/jwt",
"version": "3.2.1",
"source": {
"type": "git",
"url": "https://github.com/lcobucci/jwt.git",
"reference": "ddce703826f9c5229781933b1a39069e38e6a0f3"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/lcobucci/jwt/zipball/ddce703826f9c5229781933b1a39069e38e6a0f3",
"reference": "ddce703826f9c5229781933b1a39069e38e6a0f3",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -259,7 +375,7 @@
"php": ">=5.5" "php": ">=5.5"
}, },
"require-dev": { "require-dev": {
"mdanter/ecc": "~0.3", "mdanter/ecc": "~0.3.1",
"mikey179/vfsstream": "~1.5", "mikey179/vfsstream": "~1.5",
"phpmd/phpmd": "~2.2", "phpmd/phpmd": "~2.2",
"phpunit/php-invoker": "~1.1", "phpunit/php-invoker": "~1.1",
@ -296,7 +412,7 @@
"JWS", "JWS",
"jwt" "jwt"
], ],
"time": "2016-03-24 22:46:13" "time": "2016-10-31T20:09:32+00:00"
}, },
{ {
"name": "league/event", "name": "league/event",
@ -346,20 +462,20 @@
"event", "event",
"listener" "listener"
], ],
"time": "2015-05-21 12:24:47" "time": "2015-05-21T12:24:47+00:00"
}, },
{ {
"name": "paragonie/random_compat", "name": "paragonie/random_compat",
"version": "v1.4.1", "version": "v2.0.10",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/paragonie/random_compat.git", "url": "https://github.com/paragonie/random_compat.git",
"reference": "c7e26a21ba357863de030f0b9e701c7d04593774" "reference": "634bae8e911eefa89c1abfbf1b66da679ac8f54d"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/paragonie/random_compat/zipball/c7e26a21ba357863de030f0b9e701c7d04593774", "url": "https://api.github.com/repos/paragonie/random_compat/zipball/634bae8e911eefa89c1abfbf1b66da679ac8f54d",
"reference": "c7e26a21ba357863de030f0b9e701c7d04593774", "reference": "634bae8e911eefa89c1abfbf1b66da679ac8f54d",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -394,7 +510,7 @@
"pseudorandom", "pseudorandom",
"random" "random"
], ],
"time": "2016-03-18 20:34:03" "time": "2017-03-13T16:27:32+00:00"
} }
], ],
"aliases": [], "aliases": [],

View File

@ -46,6 +46,7 @@ $app = new App([
$privateKeyPath, $privateKeyPath,
$publicKeyPath $publicKeyPath
); );
$server->setEncryptionKey('lxZFUEsBCJ2Yb14IF2ygAHI5N4+ZAUXXaSeeJm6+twsUmIen');
// Enable the authentication code grant on the server with a token TTL of 1 hour // Enable the authentication code grant on the server with a token TTL of 1 hour
$server->enableGrantType( $server->enableGrantType(

View File

@ -42,6 +42,7 @@ $app = new App([
$privateKey, $privateKey,
$publicKey $publicKey
); );
$server->setEncryptionKey('lxZFUEsBCJ2Yb14IF2ygAHI5N4+ZAUXXaSeeJm6+twsUmIen');
// Enable the client credentials grant on the server // Enable the client credentials grant on the server
$server->enableGrantType( $server->enableGrantType(

View File

@ -42,6 +42,7 @@ $app = new App([
$privateKeyPath, $privateKeyPath,
$publicKeyPath $publicKeyPath
); );
$server->setEncryptionKey('lxZFUEsBCJ2Yb14IF2ygAHI5N4+ZAUXXaSeeJm6+twsUmIen');
// Enable the implicit grant on the server with a token TTL of 1 hour // Enable the implicit grant on the server with a token TTL of 1 hour
$server->enableGrantType(new ImplicitGrant(new \DateInterval('PT1H'))); $server->enableGrantType(new ImplicitGrant(new \DateInterval('PT1H')));

View File

@ -48,6 +48,7 @@ $app = new App([
$privateKeyPath, $privateKeyPath,
$publicKeyPath $publicKeyPath
); );
$server->setEncryptionKey('lxZFUEsBCJ2Yb14IF2ygAHI5N4+ZAUXXaSeeJm6+twsUmIen');
// Enable the authentication code grant on the server with a token TTL of 1 hour // Enable the authentication code grant on the server with a token TTL of 1 hour
$server->enableGrantType( $server->enableGrantType(

View File

@ -26,6 +26,7 @@ $app = new App([
'file://' . __DIR__ . '/../private.key', // path to private key 'file://' . __DIR__ . '/../private.key', // path to private key
'file://' . __DIR__ . '/../public.key' // path to public key 'file://' . __DIR__ . '/../public.key' // path to public key
); );
$server->setEncryptionKey('lxZFUEsBCJ2Yb14IF2ygAHI5N4+ZAUXXaSeeJm6+twsUmIen');
$grant = new PasswordGrant( $grant = new PasswordGrant(
new UserRepository(), // instance of UserRepositoryInterface new UserRepository(), // instance of UserRepositoryInterface

View File

@ -43,6 +43,7 @@ $app = new App([
$privateKeyPath, $privateKeyPath,
$publicKeyPath $publicKeyPath
); );
$server->setEncryptionKey('lxZFUEsBCJ2Yb14IF2ygAHI5N4+ZAUXXaSeeJm6+twsUmIen');
// Enable the refresh token grant on the server // Enable the refresh token grant on the server
$grant = new RefreshTokenGrant($refreshTokenRepository); $grant = new RefreshTokenGrant($refreshTokenRepository);
@ -66,10 +67,8 @@ $app->post('/access_token', function (ServerRequestInterface $request, ResponseI
} catch (OAuthServerException $exception) { } catch (OAuthServerException $exception) {
return $exception->generateHttpResponse($response); return $exception->generateHttpResponse($response);
} catch (\Exception $exception) { } catch (\Exception $exception) {
$body = new Stream('php://temp', 'r+'); $response->getBody()->write($exception->getMessage());
$body->write($exception->getMessage()); return $response->withStatus(500);
return $response->withStatus(500)->withBody($body);
} }
}); });