diff --git a/examples/public/client_credentials.php b/examples/public/client_credentials.php index db359b92..9259c0b1 100644 --- a/examples/public/client_credentials.php +++ b/examples/public/client_credentials.php @@ -1,11 +1,17 @@ enableGrantType(new ClientCredentialsGrant($clientRepository, $scopeRepository, $accessTokenRepository)); + +// App +$app = new App([Server::class => $server]); +unset($app->getContainer()['errorHandler']); + +$app->post('/access_token', function (Request $request, Response $response) { + /** @var Server $server */ + $server = $this->getContainer()->get(Server::class); + try { + return $server->respondToRequest($request); + } catch (OAuthException $e) { + return $e->generateHttpResponse(); + } catch (\Exception $e) { + return $response->withStatus(500)->write($e->getMessage()); + } +}); + +$app->run();