From 9048617e355ea0768fca3b9e5d64001851730c0f Mon Sep 17 00:00:00 2001 From: Alex Bilbie Date: Sun, 5 Apr 2015 18:18:28 +0100 Subject: [PATCH] Updated client credentials example --- examples/client-credentials/index.php | 23 ----------------- examples/public/client_credentials.php | 34 ++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 23 deletions(-) delete mode 100644 examples/client-credentials/index.php create mode 100644 examples/public/client_credentials.php 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();