diff --git a/examples/relational/Storage/RefreshTokenStorage.php b/examples/relational/Storage/RefreshTokenStorage.php index 4a32f92d..8022cc8b 100644 --- a/examples/relational/Storage/RefreshTokenStorage.php +++ b/examples/relational/Storage/RefreshTokenStorage.php @@ -6,6 +6,8 @@ use League\OAuth2\Server\Storage\RefreshTokenInterface; use League\OAuth2\Server\Storage\Adapter; use League\OAuth2\Server\Entity\RefreshTokenEntity; +use Illuminate\Database\Capsule\Manager as Capsule; + class RefreshTokenStorage extends Adapter implements RefreshTokenInterface { /** @@ -21,7 +23,12 @@ class RefreshTokenStorage extends Adapter implements RefreshTokenInterface */ public function create($token, $expireTime, $accessToken) { - die(var_dump(__METHOD__, func_get_args())); + Capsule::table('oauth_refresh_tokens') + ->insert([ + 'refresh_token' => $token, + 'access_token' => $accessToken, + 'expire_time' => $expireTime + ]); } /** diff --git a/examples/relational/authcode_grant.php b/examples/relational/authcode_grant.php index 960147f2..51774676 100644 --- a/examples/relational/authcode_grant.php +++ b/examples/relational/authcode_grant.php @@ -1,24 +1,22 @@ createFromGlobals(); $router = new \Orno\Route\RouteCollection; +$router->setStrategy(\Orno\Route\RouteStrategyInterface::RESTFUL_STRATEGY); -// Set up the OAuth 2.0 resource server +// Set up the OAuth 2.0 authorization server $server = new \League\OAuth2\Server\AuthorizationServer; $server->setSessionStorage(new Storage\SessionStorage); $server->setAccessTokenStorage(new Storage\AccessTokenStorage); @@ -30,8 +28,12 @@ $server->setAuthCodeStorage(new Storage\AuthCodeStorage); $authCodeGrant = new \League\OAuth2\Server\Grant\AuthCodeGrant(); $server->addGrantType($authCodeGrant); +$refrehTokenGrant = new \League\OAuth2\Server\Grant\RefreshTokenGrant(); +$server->addGrantType($refrehTokenGrant); + +// Routing setup $request = (new Request)->createFromGlobals(); -$server->setRequest($request); +$router = new \Orno\Route\RouteCollection; $router->get('/authorize', function (Request $request) use ($server) { @@ -96,5 +98,42 @@ $router->post('/access_token', function (Request $request) use ($server) { }); $dispatcher = $router->getDispatcher(); -$response = $dispatcher->dispatch($request->getMethod(), $request->getPathInfo()); -$response->send(); + +try { + + // A successful response + $response = $dispatcher->dispatch( + $request->getMethod(), + $request->getPathInfo() + ); + +} catch (\Orno\Http\Exception $e) { + + // A failed response + $response = $e->getJsonResponse(); + $response->setContent(json_encode(['status_code' => $e->getStatusCode(), 'message' => $e->getMessage()])); + +} catch (\League\OAuth2\Server\Exception\OAuthException $e) { + + $response = new Response(json_encode([ + 'error' => $e->errorType, + 'message' => $e->getMessage() + ]), $e->httpStatusCode); + + foreach ($e->getHttpHeaders() as $header) { + $response->headers($header); + } + +} catch (\Exception $e) { + + $response = new Orno\Http\Response; + $response->setStatusCode(500); + $response->setContent(json_encode(['status_code' => 500, 'message' => $e->getMessage()])); + +} finally { + + // Return the response + $response->headers->set('Content-type', 'application/json'); + $response->send(); + +} diff --git a/examples/relational/other_grants.php b/examples/relational/other_grants.php index 495af38b..a1c8c442 100644 --- a/examples/relational/other_grants.php +++ b/examples/relational/other_grants.php @@ -43,8 +43,8 @@ $passwordGrant->setVerifyCredentialsCallback(function ($username, $password) { }); $server->addGrantType($passwordGrant); -// $refrehTokenGrant = new \League\OAuth2\Server\Grant\RefreshTokenGrant(); -// $server->addGrantType($refrehTokenGrant); +$refrehTokenGrant = new \League\OAuth2\Server\Grant\RefreshTokenGrant(); +$server->addGrantType($refrehTokenGrant); // Routing setup $request = (new Request)->createFromGlobals(); diff --git a/tests/fuzz/grant-password.yml b/tests/fuzz/grant-password.yml index 96bcfbea..0348c5f2 100644 --- a/tests/fuzz/grant-password.yml +++ b/tests/fuzz/grant-password.yml @@ -80,6 +80,9 @@ response: - key: access_token valueRegex: /([a-zA-Z0-9]*)/ + - + key: refresh_token + valueRegex: /([a-zA-Z0-9]*)/ - key: token_type value: Bearer \ No newline at end of file