Merge pull request #1032 from thephpleague/update-examples-for-version-8

Update Examples for Version 8
This commit is contained in:
Andrew Millington 2019-07-13 19:39:38 +01:00 committed by GitHub
commit 1d9ca35fec
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 56 additions and 50 deletions

View File

@ -3,11 +3,11 @@
"slim/slim": "^3.0.0" "slim/slim": "^3.0.0"
}, },
"require-dev": { "require-dev": {
"league/event": "^2.1", "league/event": "^2.2",
"lcobucci/jwt": "^3.2", "lcobucci/jwt": "^3.3",
"psr/http-message": "^1.0", "psr/http-message": "^1.0",
"defuse/php-encryption": "^2.2", "defuse/php-encryption": "^2.2",
"zendframework/zend-diactoros": "^2.0.0" "zendframework/zend-diactoros": "^2.1.0"
}, },
"autoload": { "autoload": {
"psr-4": { "psr-4": {

67
examples/composer.lock generated
View File

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"content-hash": "97f2878428e37d1d8e5418cc85cbfa3d", "content-hash": "a7f5c3fdcadb17399bbd97f15e1b11f1",
"packages": [ "packages": [
{ {
"name": "container-interop/container-interop", "name": "container-interop/container-interop",
@ -234,16 +234,16 @@
}, },
{ {
"name": "slim/slim", "name": "slim/slim",
"version": "3.11.0", "version": "3.12.1",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/slimphp/Slim.git", "url": "https://github.com/slimphp/Slim.git",
"reference": "d378e70431e78ee92ee32ddde61ecc72edf5dc0a" "reference": "eaee12ef8d0750db62b8c548016d82fb33addb6b"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/slimphp/Slim/zipball/d378e70431e78ee92ee32ddde61ecc72edf5dc0a", "url": "https://api.github.com/repos/slimphp/Slim/zipball/eaee12ef8d0750db62b8c548016d82fb33addb6b",
"reference": "d378e70431e78ee92ee32ddde61ecc72edf5dc0a", "reference": "eaee12ef8d0750db62b8c548016d82fb33addb6b",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -301,7 +301,7 @@
"micro", "micro",
"router" "router"
], ],
"time": "2018-09-16T10:54:21+00:00" "time": "2019-04-16T16:47:29+00:00"
} }
], ],
"packages-dev": [ "packages-dev": [
@ -370,33 +370,30 @@
}, },
{ {
"name": "lcobucci/jwt", "name": "lcobucci/jwt",
"version": "3.2.4", "version": "3.3.1",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/lcobucci/jwt.git", "url": "https://github.com/lcobucci/jwt.git",
"reference": "c9704b751315d21735dc98d78d4f37bd73596da7" "reference": "a11ec5f4b4d75d1fcd04e133dede4c317aac9e18"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/lcobucci/jwt/zipball/c9704b751315d21735dc98d78d4f37bd73596da7", "url": "https://api.github.com/repos/lcobucci/jwt/zipball/a11ec5f4b4d75d1fcd04e133dede4c317aac9e18",
"reference": "c9704b751315d21735dc98d78d4f37bd73596da7", "reference": "a11ec5f4b4d75d1fcd04e133dede4c317aac9e18",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
"ext-mbstring": "*",
"ext-openssl": "*", "ext-openssl": "*",
"php": ">=5.5" "php": "^5.6 || ^7.0"
}, },
"require-dev": { "require-dev": {
"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",
"phpunit/phpunit": "~4.5", "phpunit/phpunit": "^5.7 || ^7.3",
"squizlabs/php_codesniffer": "~2.3" "squizlabs/php_codesniffer": "~2.3"
}, },
"suggest": {
"mdanter/ecc": "Required to use Elliptic Curves based algorithms."
},
"type": "library", "type": "library",
"extra": { "extra": {
"branch-alias": { "branch-alias": {
@ -424,20 +421,20 @@
"JWS", "JWS",
"jwt" "jwt"
], ],
"time": "2018-08-03T11:23:50+00:00" "time": "2019-05-24T18:30:49+00:00"
}, },
{ {
"name": "league/event", "name": "league/event",
"version": "2.1.2", "version": "2.2.0",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/thephpleague/event.git", "url": "https://github.com/thephpleague/event.git",
"reference": "e4bfc88dbcb60c8d8a2939a71f9813e141bbe4cd" "reference": "d2cc124cf9a3fab2bb4ff963307f60361ce4d119"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/thephpleague/event/zipball/e4bfc88dbcb60c8d8a2939a71f9813e141bbe4cd", "url": "https://api.github.com/repos/thephpleague/event/zipball/d2cc124cf9a3fab2bb4ff963307f60361ce4d119",
"reference": "e4bfc88dbcb60c8d8a2939a71f9813e141bbe4cd", "reference": "d2cc124cf9a3fab2bb4ff963307f60361ce4d119",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -445,7 +442,7 @@
}, },
"require-dev": { "require-dev": {
"henrikbjorn/phpspec-code-coverage": "~1.0.1", "henrikbjorn/phpspec-code-coverage": "~1.0.1",
"phpspec/phpspec": "~2.0.0" "phpspec/phpspec": "^2.2"
}, },
"type": "library", "type": "library",
"extra": { "extra": {
@ -474,7 +471,7 @@
"event", "event",
"listener" "listener"
], ],
"time": "2015-05-21T12:24:47+00:00" "time": "2018-11-26T11:52:41+00:00"
}, },
{ {
"name": "paragonie/random_compat", "name": "paragonie/random_compat",
@ -523,16 +520,16 @@
}, },
{ {
"name": "psr/http-factory", "name": "psr/http-factory",
"version": "1.0.0", "version": "1.0.1",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/php-fig/http-factory.git", "url": "https://github.com/php-fig/http-factory.git",
"reference": "378bfe27931ecc54ff824a20d6f6bfc303bbd04c" "reference": "12ac7fcd07e5b077433f5f2bee95b3a771bf61be"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/php-fig/http-factory/zipball/378bfe27931ecc54ff824a20d6f6bfc303bbd04c", "url": "https://api.github.com/repos/php-fig/http-factory/zipball/12ac7fcd07e5b077433f5f2bee95b3a771bf61be",
"reference": "378bfe27931ecc54ff824a20d6f6bfc303bbd04c", "reference": "12ac7fcd07e5b077433f5f2bee95b3a771bf61be",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -571,20 +568,20 @@
"request", "request",
"response" "response"
], ],
"time": "2018-07-30T21:54:04+00:00" "time": "2019-04-30T12:38:16+00:00"
}, },
{ {
"name": "zendframework/zend-diactoros", "name": "zendframework/zend-diactoros",
"version": "2.0.0", "version": "2.1.3",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/zendframework/zend-diactoros.git", "url": "https://github.com/zendframework/zend-diactoros.git",
"reference": "0bae78192e634774b5584f0210c1232da82cb1ff" "reference": "279723778c40164bcf984a2df12ff2c6ec5e61c1"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/zendframework/zend-diactoros/zipball/0bae78192e634774b5584f0210c1232da82cb1ff", "url": "https://api.github.com/repos/zendframework/zend-diactoros/zipball/279723778c40164bcf984a2df12ff2c6ec5e61c1",
"reference": "0bae78192e634774b5584f0210c1232da82cb1ff", "reference": "279723778c40164bcf984a2df12ff2c6ec5e61c1",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -607,8 +604,8 @@
"type": "library", "type": "library",
"extra": { "extra": {
"branch-alias": { "branch-alias": {
"dev-master": "2.0.x-dev", "dev-master": "2.1.x-dev",
"dev-develop": "2.1.x-dev", "dev-develop": "2.2.x-dev",
"dev-release-1.8": "1.8.x-dev" "dev-release-1.8": "1.8.x-dev"
} }
}, },
@ -637,7 +634,7 @@
"psr", "psr",
"psr-7" "psr-7"
], ],
"time": "2018-09-27T19:49:04+00:00" "time": "2019-07-10T16:13:25+00:00"
} }
], ],
"aliases": [], "aliases": [],

View File

@ -14,16 +14,33 @@ use OAuth2ServerExamples\Entities\ClientEntity;
class ClientRepository implements ClientRepositoryInterface class ClientRepository implements ClientRepositoryInterface
{ {
const CLIENT_NAME = 'My Awesome App';
const REDIRECT_URI = 'http://foo/bar';
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function getClientEntity($clientIdentifier, $grantType = null, $clientSecret = null, $mustValidateSecret = true) public function getClientEntity($clientIdentifier)
{
$client = new ClientEntity();
$client->setIdentifier($clientIdentifier);
$client->setName(self::CLIENT_NAME);
$client->setRedirectUri(self::REDIRECT_URI);
return $client;
}
/**
* {@inheritdoc}
*/
public function validateClient($clientIdentifier, $clientSecret, $grantType)
{ {
$clients = [ $clients = [
'myawesomeapp' => [ 'myawesomeapp' => [
'secret' => password_hash('abc123', PASSWORD_BCRYPT), 'secret' => password_hash('abc123', PASSWORD_BCRYPT),
'name' => 'My Awesome App', 'name' => self::CLIENT_NAME,
'redirect_uri' => 'http://foo/bar', 'redirect_uri' => self::REDIRECT_URI,
'is_confidential' => true, 'is_confidential' => true,
], ],
]; ];
@ -34,18 +51,10 @@ class ClientRepository implements ClientRepositoryInterface
} }
if ( if (
$mustValidateSecret === true $clients[$clientIdentifier]['is_confidential'] === true
&& $clients[$clientIdentifier]['is_confidential'] === true
&& password_verify($clientSecret, $clients[$clientIdentifier]['secret']) === false && password_verify($clientSecret, $clients[$clientIdentifier]['secret']) === false
) { ) {
return; return;
} }
$client = new ClientEntity();
$client->setIdentifier($clientIdentifier);
$client->setName($clients[$clientIdentifier]['name']);
$client->setRedirectUri($clients[$clientIdentifier]['redirect_uri']);
return $client;
} }
} }