diff --git a/examples/public/password.php b/examples/public/password.php index fff4717b..efeed2f0 100644 --- a/examples/public/password.php +++ b/examples/public/password.php @@ -1,34 +1,50 @@ addRepository(new ClientRepository()); -$server->addRepository(new ScopeRepository()); -$server->addRepository(new AccessTokenRepository()); -$server->addRepository(new UserRepository()); -// Enable the password grant -$server->enableGrantType('PasswordGrant'); +// Init our repositories +$clientRepository = new ClientRepository(); +$scopeRepository = new ScopeRepository(); +$accessTokenRepository = new AccessTokenRepository(); +$userRepository = new UserRepository(); -// Setup app + routing -$application = new \Proton\Application(); -$application->post('/access_token', function (Request $request) use ($server) { +// Enable the client credentials grant on the server +$server->enableGrantType(new PasswordGrant( + $userRepository, + $clientRepository, + $scopeRepository, + $accessTokenRepository +)); + +// App +$app = new App([Server::class => $server]); + +$app->post('/access_token', function (Request $request, Response $response) { + /** @var Server $server */ + $server = $this->getContainer()->get(Server::class); try { - return $server->getAccessTokenResponse($request); - } catch (OAuthException $e) { + return $server->respondToRequest($request); + } catch (OAuthServerException $e) { return $e->generateHttpResponse(); + } catch (\Exception $e) { + return $response->withStatus(500)->write($e->getMessage()); } }); -// Run the app -$application->run(); +$app->run(); diff --git a/examples/src/Repositories/UserRepository.php b/examples/src/Repositories/UserRepository.php index d006dab1..1ad9914d 100644 --- a/examples/src/Repositories/UserRepository.php +++ b/examples/src/Repositories/UserRepository.php @@ -1,22 +1,25 @@