Updated examples

This commit is contained in:
Alex Bilbie 2016-01-13 00:47:41 +00:00
parent 20ad5d251c
commit 94b221c8a1
4 changed files with 248 additions and 27 deletions

View File

@ -6,8 +6,8 @@
} }
], ],
"require": { "require": {
"slim/slim": "3.0.0-RC2", "slim/slim": "3.0.*",
"league/oauth2-server": "dev-v5-one" "league/oauth2-server": "dev-V5-WIP"
}, },
"autoload": { "autoload": {
"psr-4": { "psr-4": {

251
examples/composer.lock generated
View File

@ -4,8 +4,8 @@
"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": "bf607d2626a69ff12f1099d3853c138b", "hash": "ff6f832d21c141662627622e68079ca5",
"content-hash": "38198bbba51d99684b5d1b50e08b3019", "content-hash": "f08d5c7c3ede910150d75ad3c56d1b46",
"packages": [ "packages": [
{ {
"name": "container-interop/container-interop", "name": "container-interop/container-interop",
@ -34,6 +34,64 @@
"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" "time": "2014-12-30 15:22:37"
}, },
{
"name": "lcobucci/jwt",
"version": "3.1.0",
"source": {
"type": "git",
"url": "https://github.com/lcobucci/jwt.git",
"reference": "31499db4e692b343cec7ff345932899f98fde1cf"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/lcobucci/jwt/zipball/31499db4e692b343cec7ff345932899f98fde1cf",
"reference": "31499db4e692b343cec7ff345932899f98fde1cf",
"shasum": ""
},
"require": {
"ext-openssl": "*",
"php": ">=5.5"
},
"require-dev": {
"mdanter/ecc": "~0.3",
"mikey179/vfsstream": "~1.5",
"phpmd/phpmd": "~2.2",
"phpunit/php-invoker": "~1.1",
"phpunit/phpunit": "~4.5",
"squizlabs/php_codesniffer": "~2.3"
},
"suggest": {
"mdanter/ecc": "Required to use Elliptic Curves based algorithms."
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "3.1-dev"
}
},
"autoload": {
"psr-4": {
"Lcobucci\\JWT\\": "src"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"BSD-3-Clause"
],
"authors": [
{
"name": "Luís Otávio Cobucci Oblonczyk",
"email": "lcobucci@gmail.com",
"role": "Developer"
}
],
"description": "A simple library to work with JSON Web Token and JSON Web Signature",
"keywords": [
"JWS",
"jwt"
],
"time": "2015-11-15 01:42:47"
},
{ {
"name": "league/event", "name": "league/event",
"version": "2.1.2", "version": "2.1.2",
@ -86,15 +144,17 @@
}, },
{ {
"name": "league/oauth2-server", "name": "league/oauth2-server",
"version": "dev-v5-one", "version": "dev-V5-WIP",
"dist": { "dist": {
"type": "path", "type": "path",
"url": "../", "url": "../",
"reference": "82413513e8002dc197a2fd9f13059eb88cd78ac1", "reference": "59080a831926d6291fbc7854ff8d25427c374263",
"shasum": null "shasum": null
}, },
"require": { "require": {
"lcobucci/jwt": "^3.1",
"league/event": "~2.1", "league/event": "~2.1",
"namshi/jose": "^6.0",
"php": ">=5.5.9", "php": ">=5.5.9",
"zendframework/zend-diactoros": "~1.1" "zendframework/zend-diactoros": "~1.1"
}, },
@ -108,7 +168,15 @@
"mockery/mockery": "0.9.*", "mockery/mockery": "0.9.*",
"phpunit/phpunit": "4.8.*" "phpunit/phpunit": "4.8.*"
}, },
"bin": [
"bin/generate-crypto-key"
],
"type": "library", "type": "library",
"extra": {
"branch-alias": {
"dev-V5-WIP": "5.0-dev"
}
},
"autoload": { "autoload": {
"psr-4": { "psr-4": {
"League\\OAuth2\\Server\\": "src/" "League\\OAuth2\\Server\\": "src/"
@ -149,6 +217,62 @@
"server" "server"
] ]
}, },
{
"name": "namshi/jose",
"version": "6.0.3",
"source": {
"type": "git",
"url": "https://github.com/namshi/jose.git",
"reference": "e214c25ce0deed923ef6b299fbad87a822b51b2c"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/namshi/jose/zipball/e214c25ce0deed923ef6b299fbad87a822b51b2c",
"reference": "e214c25ce0deed923ef6b299fbad87a822b51b2c",
"shasum": ""
},
"require": {
"ext-date": "*",
"ext-hash": "*",
"ext-json": "*",
"ext-openssl": "*",
"ext-pcre": "*",
"ext-spl": "*",
"php": ">=5.4.8",
"phpseclib/phpseclib": "1.0.0"
},
"require-dev": {
"phpunit/phpunit": "~4.5",
"satooshi/php-coveralls": "dev-master"
},
"type": "library",
"autoload": {
"psr-0": {
"Namshi\\JOSE": "src/",
"Namshi\\JOSE\\Test": "test/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Alessandro Nadalin",
"email": "alessandro.nadalin@gmail.com"
}
],
"description": "JSON Object Signing and Encryption library for PHP.",
"keywords": [
"JSON Web Signature",
"JSON Web Token",
"JWS",
"json",
"jwt",
"token"
],
"time": "2015-11-13 08:01:01"
},
{ {
"name": "nikic/fast-route", "name": "nikic/fast-route",
"version": "v0.6.0", "version": "v0.6.0",
@ -192,6 +316,100 @@
], ],
"time": "2015-06-18 19:15:47" "time": "2015-06-18 19:15:47"
}, },
{
"name": "phpseclib/phpseclib",
"version": "1.0.0",
"source": {
"type": "git",
"url": "https://github.com/phpseclib/phpseclib.git",
"reference": "844134df95e42b93ed5506a2d11ca5accda99412"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/phpseclib/phpseclib/zipball/844134df95e42b93ed5506a2d11ca5accda99412",
"reference": "844134df95e42b93ed5506a2d11ca5accda99412",
"shasum": ""
},
"require": {
"php": ">=5.0.0"
},
"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-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-0": {
"Crypt": "phpseclib/",
"File": "phpseclib/",
"Math": "phpseclib/",
"Net": "phpseclib/",
"System": "phpseclib/"
},
"files": [
"phpseclib/Crypt/Random.php"
]
},
"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 02:22:12"
},
{ {
"name": "pimple/pimple", "name": "pimple/pimple",
"version": "v3.0.2", "version": "v3.0.2",
@ -289,16 +507,16 @@
}, },
{ {
"name": "slim/slim", "name": "slim/slim",
"version": "3.0.0-RC2", "version": "3.0.0",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/slimphp/Slim.git", "url": "https://github.com/slimphp/Slim.git",
"reference": "c181a3a7666677fcf5dee2c03c504d5731262745" "reference": "3b06f0f2d84dabbe81b6cea46ace46a3e883253e"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/slimphp/Slim/zipball/c181a3a7666677fcf5dee2c03c504d5731262745", "url": "https://api.github.com/repos/slimphp/Slim/zipball/3b06f0f2d84dabbe81b6cea46ace46a3e883253e",
"reference": "c181a3a7666677fcf5dee2c03c504d5731262745", "reference": "3b06f0f2d84dabbe81b6cea46ace46a3e883253e",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -351,20 +569,20 @@
"micro", "micro",
"router" "router"
], ],
"time": "2015-11-09 10:57:43" "time": "2015-12-07 14:11:09"
}, },
{ {
"name": "zendframework/zend-diactoros", "name": "zendframework/zend-diactoros",
"version": "1.1.4", "version": "1.3.3",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/zendframework/zend-diactoros.git", "url": "https://github.com/zendframework/zend-diactoros.git",
"reference": "3f0ce6c0ba2106e018fb514a9f09dbb91eb6bfd0" "reference": "4d54fde709664562eb63356f0250d527824d05de"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/zendframework/zend-diactoros/zipball/3f0ce6c0ba2106e018fb514a9f09dbb91eb6bfd0", "url": "https://api.github.com/repos/zendframework/zend-diactoros/zipball/4d54fde709664562eb63356f0250d527824d05de",
"reference": "3f0ce6c0ba2106e018fb514a9f09dbb91eb6bfd0", "reference": "4d54fde709664562eb63356f0250d527824d05de",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -381,8 +599,8 @@
"type": "library", "type": "library",
"extra": { "extra": {
"branch-alias": { "branch-alias": {
"dev-master": "1.0-dev", "dev-master": "1.3-dev",
"dev-develop": "1.1-dev" "dev-develop": "1.4-dev"
} }
}, },
"autoload": { "autoload": {
@ -401,14 +619,13 @@
"psr", "psr",
"psr-7" "psr-7"
], ],
"time": "2015-10-16 15:24:05" "time": "2016-01-04 21:37:32"
} }
], ],
"packages-dev": [], "packages-dev": [],
"aliases": [], "aliases": [],
"minimum-stability": "stable", "minimum-stability": "stable",
"stability-flags": { "stability-flags": {
"slim/slim": 5,
"league/oauth2-server": 20 "league/oauth2-server": 20
}, },
"prefer-stable": false, "prefer-stable": false,

View File

@ -15,7 +15,7 @@ use Slim\Http\Response;
include(__DIR__ . '/../vendor/autoload.php'); include(__DIR__ . '/../vendor/autoload.php');
// Setup the authorization server // Setup the authorization server
$server = new Server(); $server = new Server('file://' . __DIR__ . '/../private.key');
// Init our repositories // Init our repositories
$clientRepository = new ClientRepository(); $clientRepository = new ClientRepository();
@ -30,7 +30,7 @@ $app = new App([Server::class => $server]);
$app->post('/access_token', function (Request $request, Response $response) { $app->post('/access_token', function (Request $request, Response $response) {
/** @var Server $server */ /** @var Server $server */
$server = $this->getContainer()->get(Server::class); $server = $this->get(Server::class);
try { try {
return $server->respondToRequest($request); return $server->respondToRequest($request);
} catch (OAuthServerException $e) { } catch (OAuthServerException $e) {

View File

@ -6,6 +6,7 @@ use League\OAuth2\Server\Server;
use OAuth2ServerExamples\Repositories\AccessTokenRepository; use OAuth2ServerExamples\Repositories\AccessTokenRepository;
use OAuth2ServerExamples\Repositories\ClientRepository; use OAuth2ServerExamples\Repositories\ClientRepository;
use OAuth2ServerExamples\Repositories\RefreshTokenRepository;
use OAuth2ServerExamples\Repositories\ScopeRepository; use OAuth2ServerExamples\Repositories\ScopeRepository;
use OAuth2ServerExamples\Repositories\UserRepository; use OAuth2ServerExamples\Repositories\UserRepository;
@ -16,28 +17,31 @@ use Slim\Http\Response;
include(__DIR__ . '/../vendor/autoload.php'); include(__DIR__ . '/../vendor/autoload.php');
// Setup the authorization server // Setup the authorization server
$server = new Server(); $server = new Server('file://' . __DIR__ . '/../private.key');
// Init our repositories // Init our repositories
$userRepository = new UserRepository();
$clientRepository = new ClientRepository(); $clientRepository = new ClientRepository();
$scopeRepository = new ScopeRepository(); $scopeRepository = new ScopeRepository();
$accessTokenRepository = new AccessTokenRepository(); $accessTokenRepository = new AccessTokenRepository();
$userRepository = new UserRepository(); $refreshTokenRepository = new RefreshTokenRepository();
// Enable the client credentials grant on the server // Enable the client credentials grant on the server
$server->enableGrantType(new PasswordGrant( $passwordGrant = new PasswordGrant(
$userRepository, $userRepository,
$clientRepository, $clientRepository,
$scopeRepository, $scopeRepository,
$accessTokenRepository $accessTokenRepository,
)); $refreshTokenRepository
);
$server->enableGrantType($passwordGrant);
// App // App
$app = new App([Server::class => $server]); $app = new App([Server::class => $server]);
$app->post('/access_token', function (Request $request, Response $response) { $app->post('/access_token', function (Request $request, Response $response) {
/** @var Server $server */ /** @var Server $server */
$server = $this->getContainer()->get(Server::class); $server = $this->get(Server::class);
try { try {
return $server->respondToRequest($request); return $server->respondToRequest($request);
} catch (OAuthServerException $e) { } catch (OAuthServerException $e) {