diff --git a/examples/client-credentials/index.php b/examples/client-credentials/index.php deleted file mode 100644 index de29ebe8..00000000 --- a/examples/client-credentials/index.php +++ /dev/null @@ -1,23 +0,0 @@ -addRepository(new \OAuth2ServerExamples\Repositories\ClientRepository()); -$server->addRepository(new \OAuth2ServerExamples\Repositories\ScopeRepository()); -$server->addRepository(new \OAuth2ServerExamples\Repositories\AccessTokenRepository()); - -// Enable the client credentials grant which will return access tokens that last for 24 hours -$server->enableGrantType('ClientCredentialsGrant', null, new \DateInterval('PT24H')); - -// Setup the routing -$application = new \Proton\Application(); -$application->post('/access_token', function (Request $request) use ($server) { - return $server->getAccessTokenResponse($request); -}); - -// Run the app -$application->run(); diff --git a/examples/public/client_credentials.php b/examples/public/client_credentials.php new file mode 100644 index 00000000..e129ac2b --- /dev/null +++ b/examples/public/client_credentials.php @@ -0,0 +1,34 @@ +addRepository(new ClientRepository()); +$server->addRepository(new ScopeRepository()); +$server->addRepository(new AccessTokenRepository()); + +// Enable the client credentials grant which will return access tokens that last for 24 hours +$server->enableGrantType('ClientCredentialsGrant', null, new \DateInterval('PT24H')); + +// Setup routing +$application = new \Proton\Application(); +$application->post('/access_token', function (Request $request) use ($server) { + + try { + return $server->getAccessTokenResponse($request); + } catch (OAuthException $e) { + return $e->generateHttpResponse(); + } + +}); + +// Run the app +$application->run();