Skip to content

Commit

Permalink
Merge 41882e8 into 3fc3b91
Browse files Browse the repository at this point in the history
  • Loading branch information
bakura10 committed Jul 3, 2014
2 parents 3fc3b91 + 41882e8 commit f7b528f
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 3 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
11 changes: 11 additions & 0 deletions config/module.config.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,17 @@
'action' => 'token'
]
]
],

'revoke' => [
'type' => 'Literal',
'options' => [
'route' => '/revoke',
'defaults' => [
'controller' => 'ZfrOAuth2Module\Server\Controller\TokenController',
'action' => 'revoke'
]
]
]
]
]
Expand Down
15 changes: 15 additions & 0 deletions src/ZfrOAuth2Module/Server/Controller/TokenController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down

0 comments on commit f7b528f

Please sign in to comment.