Updated refresh token example

This commit is contained in:
Alex Bilbie 2016-01-17 14:25:44 +00:00
parent 168e7640c6
commit 3c4347e385

View File

@ -8,7 +8,6 @@ use OAuth2ServerExamples\Repositories\AccessTokenRepository;
use OAuth2ServerExamples\Repositories\ClientRepository; use OAuth2ServerExamples\Repositories\ClientRepository;
use OAuth2ServerExamples\Repositories\RefreshTokenRepository; use OAuth2ServerExamples\Repositories\RefreshTokenRepository;
use OAuth2ServerExamples\Repositories\ScopeRepository; use OAuth2ServerExamples\Repositories\ScopeRepository;
use OAuth2ServerExamples\Repositories\UserRepository;
use Slim\App; use Slim\App;
use Slim\Http\Request; use Slim\Http\Request;
@ -16,28 +15,33 @@ use Slim\Http\Response;
include(__DIR__ . '/../vendor/autoload.php'); include(__DIR__ . '/../vendor/autoload.php');
// Setup the authorization server
$server = new Server('file://' . __DIR__ . '/../private.key');
// App
$app = new App([Server::class => function () {
// 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();
$refreshTokenRepository = new RefreshTokenRepository(); $refreshTokenRepository = new RefreshTokenRepository();
// Enable the client credentials grant on the server $privateKeyPath = 'file://' . __DIR__ . '/../private.key';
$refreshTokenGrant = new RefreshTokenGrant( $publicKeyPath = 'file://' . __DIR__ . '/../public.key';
'file://' . __DIR__ . '/../public.key',
$clientRepository,
$scopeRepository,
$accessTokenRepository,
$refreshTokenRepository
);
$server->enableGrantType($refreshTokenGrant);
// App // Setup the authorization server
$app = new App([Server::class => $server]); $server = new Server(
$clientRepository,
$accessTokenRepository,
$scopeRepository,
$privateKeyPath,
$publicKeyPath
);
// Enable the refresh token grant on the server
$server->enableGrantType(new RefreshTokenGrant($refreshTokenRepository), new \DateInterval('PT1H'));
return $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 */