From 2e2793ba8acbc766d5efc4b09dafe46d51ba3a4f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Gallego?= Date: Sun, 29 Jun 2014 19:39:32 +0200 Subject: [PATCH 1/2] Add revocation --- composer.json | 2 +- config/module.config.php | 11 +++++++++++ .../Server/Controller/TokenController.php | 15 +++++++++++++++ .../Server/Factory/AuthorizationServerFactory.php | 8 +++++++- 4 files changed, 34 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 43ee826..5f13353 100644 --- a/composer.json +++ b/composer.json @@ -24,7 +24,7 @@ "zendframework/zend-console": "~2.2", "zendframework/zend-stdlib": "~2.2", "doctrine/doctrine-module": "~0.8", - "zfr/zfr-oauth2-server": "0.4.*" + "zfr/zfr-oauth2-server": "0.5.*" }, "require-dev": { "phpunit/phpunit": "~4.0", diff --git a/config/module.config.php b/config/module.config.php index dd6954b..6407278 100644 --- a/config/module.config.php +++ b/config/module.config.php @@ -82,6 +82,17 @@ 'action' => 'token' ] ] + ], + + 'revoke' => [ + 'type' => 'Literal', + 'options' => [ + 'route' => '/revoke', + 'defaults' => [ + 'controller' => 'ZfrOAuth2Module\Server\Controller\TokenController', + 'action' => 'revoke' + ] + ] ] ] ] diff --git a/src/ZfrOAuth2Module/Server/Controller/TokenController.php b/src/ZfrOAuth2Module/Server/Controller/TokenController.php index e5f2910..9944d45 100644 --- a/src/ZfrOAuth2Module/Server/Controller/TokenController.php +++ b/src/ZfrOAuth2Module/Server/Controller/TokenController.php @@ -58,6 +58,21 @@ public function tokenAction() return $this->authorizationServer->handleTokenRequest($this->request); } + /** + * Handle a token revocation request + * + * @return \Zend\Http\Response|null + */ + public function revokeAction() + { + // Can't do anything if not HTTP request... + if (!$this->request instanceof HttpRequest) { + return null; + } + + return $this->authorizationServer->handleRevocationRequest($this->request); + } + /** * Delete expired tokens * diff --git a/src/ZfrOAuth2Module/Server/Factory/AuthorizationServerFactory.php b/src/ZfrOAuth2Module/Server/Factory/AuthorizationServerFactory.php index 9f836b9..21eb8d1 100644 --- a/src/ZfrOAuth2Module/Server/Factory/AuthorizationServerFactory.php +++ b/src/ZfrOAuth2Module/Server/Factory/AuthorizationServerFactory.php @@ -47,6 +47,12 @@ public function createService(ServiceLocatorInterface $serviceLocator) $grants[] = $grantPluginManager->get($grant); } - return new AuthorizationServer($clientService, $grants); + /** @var \ZfrOAuth2\Server\Service\TokenService $accessTokenService */ + $accessTokenService = $serviceLocator->get('ZfrOAuth2\Server\Service\AccessTokenService'); + + /** @var \ZfrOAuth2\Server\Service\TokenService $refreshTokenService */ + $refreshTokenService = $serviceLocator->get('ZfrOAuth2\Server\Service\RefreshTokenService'); + + return new AuthorizationServer($clientService, $grants, $accessTokenService, $refreshTokenService); } } From 41882e8c1a7a8eee0b01ee9ce257ef76de480386 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Gallego?= Date: Thu, 3 Jul 2014 14:44:01 +0200 Subject: [PATCH 2/2] Add test --- README.md | 2 +- .../Server/Controller/TokenControllerTest.php | 20 +++++++++++++++++++ .../AuthorizationServerFactoryTest.php | 10 ++++++++++ 3 files changed, 31 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 57f44d2..395fc00 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,7 @@ Please note that until I reach 1.0, I **WILL NOT** follow semantic version. This Installation is only officially supported using Composer: ```sh -php composer.phar require zfr/zfr-oauth2-server-module:0.4.* +php composer.phar require zfr/zfr-oauth2-server-module:0.5.* ``` Copy-paste the `zfr_oauth2_server.global.php.dist` file to your `autoload` folder, and enable the module by adding diff --git a/tests/ZfrOAuth2ModuleTest/Server/Controller/TokenControllerTest.php b/tests/ZfrOAuth2ModuleTest/Server/Controller/TokenControllerTest.php index 3e97804..46b5d44 100644 --- a/tests/ZfrOAuth2ModuleTest/Server/Controller/TokenControllerTest.php +++ b/tests/ZfrOAuth2ModuleTest/Server/Controller/TokenControllerTest.php @@ -65,4 +65,24 @@ public function testDelegateToAuthorizationServerIfHttpRequest() $this->assertSame($response, $controller->tokenAction($request)); } + + public function testCanRevokeToken() + { + $authorizationServer = $this->getMock('ZfrOAuth2\Server\AuthorizationServer', [], [], '', false); + $controller = new TokenController($authorizationServer); + + $request = new HttpRequest(); + $response = new HttpResponse(); + + $reflProperty = new \ReflectionProperty($controller, 'request'); + $reflProperty->setAccessible(true); + $reflProperty->setValue($controller, $request); + + $authorizationServer->expects($this->once()) + ->method('handleRevocationRequest') + ->with($request) + ->will($this->returnValue($response)); + + $this->assertSame($response, $controller->revokeAction($request)); + } } diff --git a/tests/ZfrOAuth2ModuleTest/Server/Factory/AuthorizationServerFactoryTest.php b/tests/ZfrOAuth2ModuleTest/Server/Factory/AuthorizationServerFactoryTest.php index 15398e9..7b55e08 100644 --- a/tests/ZfrOAuth2ModuleTest/Server/Factory/AuthorizationServerFactoryTest.php +++ b/tests/ZfrOAuth2ModuleTest/Server/Factory/AuthorizationServerFactoryTest.php @@ -52,6 +52,16 @@ public function testCanCreateFromFactory() $grantPluginManager ); + $serviceManager->setService( + 'ZfrOAuth2\Server\Service\AccessTokenService', + $this->getMock('ZfrOAuth2\Server\Service\TokenService', [], [], '', false) + ); + + $serviceManager->setService( + 'ZfrOAuth2\Server\Service\RefreshTokenService', + $this->getMock('ZfrOAuth2\Server\Service\TokenService', [], [], '', false) + ); + $grantPluginManager->expects($this->once()) ->method('get') ->with('MyGrant')