From e513b4211705f53d42a8979afedce399d0241928 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juli=C3=A1n=20Guti=C3=A9rrez?= Date: Mon, 28 Mar 2016 12:10:51 +0200 Subject: [PATCH] remove access token repository from response types --- src/Grant/AuthCodeGrant.php | 6 ++--- src/Grant/ImplicitGrant.php | 6 ++--- src/ResponseTypes/AbstractResponseType.php | 14 ---------- .../ResponseTypes/BearerResponseTypeTest.php | 26 +++++++++---------- 4 files changed, 18 insertions(+), 34 deletions(-) diff --git a/src/Grant/AuthCodeGrant.php b/src/Grant/AuthCodeGrant.php index 251c782d..93e7eb51 100644 --- a/src/Grant/AuthCodeGrant.php +++ b/src/Grant/AuthCodeGrant.php @@ -145,7 +145,7 @@ class AuthCodeGrant extends AbstractAuthorizeGrant ), ]); - $htmlResponse = new HtmlResponse($this->accessTokenRepository); + $htmlResponse = new HtmlResponse(); $htmlResponse->setStatusCode(403); $htmlResponse->setHtml($html); @@ -163,7 +163,7 @@ class AuthCodeGrant extends AbstractAuthorizeGrant ), ]); - $htmlResponse = new HtmlResponse($this->accessTokenRepository); + $htmlResponse = new HtmlResponse(); $htmlResponse->setStatusCode(200); $htmlResponse->setHtml($html); $htmlResponse->setHeader('set-cookie', sprintf( @@ -215,7 +215,7 @@ class AuthCodeGrant extends AbstractAuthorizeGrant ) ); - $response = new RedirectResponse($this->accessTokenRepository); + $response = new RedirectResponse(); $response->setRedirectUri( $this->makeRedirectUri( $redirectUri, diff --git a/src/Grant/ImplicitGrant.php b/src/Grant/ImplicitGrant.php index 11950a78..e274b186 100644 --- a/src/Grant/ImplicitGrant.php +++ b/src/Grant/ImplicitGrant.php @@ -141,7 +141,7 @@ class ImplicitGrant extends AbstractAuthorizeGrant ), ]); - $htmlResponse = new HtmlResponse($this->accessTokenRepository); + $htmlResponse = new HtmlResponse(); $htmlResponse->setStatusCode(403); $htmlResponse->setHtml($html); @@ -159,7 +159,7 @@ class ImplicitGrant extends AbstractAuthorizeGrant ), ]); - $htmlResponse = new HtmlResponse($this->accessTokenRepository); + $htmlResponse = new HtmlResponse(); $htmlResponse->setStatusCode(200); $htmlResponse->setHtml($html); $htmlResponse->setHeader('set-cookie', sprintf( @@ -201,7 +201,7 @@ class ImplicitGrant extends AbstractAuthorizeGrant $redirectPayload['token_type'] = 'bearer'; $redirectPayload['expires_in'] = time() - $accessToken->getExpiryDateTime()->getTimestamp(); - $response = new RedirectResponse($this->accessTokenRepository); + $response = new RedirectResponse(); $response->setRedirectUri( $this->makeRedirectUri( $redirectUri, diff --git a/src/ResponseTypes/AbstractResponseType.php b/src/ResponseTypes/AbstractResponseType.php index e693d85b..c42e1d87 100644 --- a/src/ResponseTypes/AbstractResponseType.php +++ b/src/ResponseTypes/AbstractResponseType.php @@ -13,7 +13,6 @@ namespace League\OAuth2\Server\ResponseTypes; use League\OAuth2\Server\CryptTrait; use League\OAuth2\Server\Entities\Interfaces\AccessTokenEntityInterface; use League\OAuth2\Server\Entities\Interfaces\RefreshTokenEntityInterface; -use League\OAuth2\Server\Repositories\AccessTokenRepositoryInterface; abstract class AbstractResponseType implements ResponseTypeInterface { @@ -29,19 +28,6 @@ abstract class AbstractResponseType implements ResponseTypeInterface */ protected $refreshToken; - /** - * @var \League\OAuth2\Server\Repositories\AccessTokenRepositoryInterface - */ - protected $accessTokenRepository; - - /** - * @param \League\OAuth2\Server\Repositories\AccessTokenRepositoryInterface $accessTokenRepository - */ - public function __construct(AccessTokenRepositoryInterface $accessTokenRepository) - { - $this->accessTokenRepository = $accessTokenRepository; - } - /** * {@inheritdoc} */ diff --git a/tests/ResponseTypes/BearerResponseTypeTest.php b/tests/ResponseTypes/BearerResponseTypeTest.php index a8b62f0e..df0639a1 100644 --- a/tests/ResponseTypes/BearerResponseTypeTest.php +++ b/tests/ResponseTypes/BearerResponseTypeTest.php @@ -18,9 +18,7 @@ class BearerResponseTypeTest extends \PHPUnit_Framework_TestCase { public function testGenerateHttpResponse() { - $accessTokenRepositoryMock = $this->getMockBuilder(AccessTokenRepositoryInterface::class)->getMock(); - - $responseType = new BearerTokenResponse($accessTokenRepositoryMock); + $responseType = new BearerTokenResponse(); $responseType->setPrivateKeyPath('file://' . __DIR__ . '/../Stubs/private.key'); $responseType->setPublicKeyPath('file://' . __DIR__ . '/../Stubs/public.key'); @@ -62,10 +60,7 @@ class BearerResponseTypeTest extends \PHPUnit_Framework_TestCase public function testDetermineAccessTokenInHeaderValidToken() { - $accessTokenRepositoryMock = $this->getMockBuilder(AccessTokenRepositoryInterface::class)->getMock(); - $accessTokenRepositoryMock->method('isAccessTokenRevoked')->willReturn(false); - - $responseType = new BearerTokenResponse($accessTokenRepositoryMock); + $responseType = new BearerTokenResponse(); $responseType->setPrivateKeyPath('file://' . __DIR__ . '/../Stubs/private.key'); $responseType->setPublicKeyPath('file://' . __DIR__ . '/../Stubs/public.key'); @@ -89,6 +84,9 @@ class BearerResponseTypeTest extends \PHPUnit_Framework_TestCase $response = $responseType->generateHttpResponse(new Response()); $json = json_decode((string) $response->getBody()); + $accessTokenRepositoryMock = $this->getMockBuilder(AccessTokenRepositoryInterface::class)->getMock(); + $accessTokenRepositoryMock->method('isAccessTokenRevoked')->willReturn(false); + $authorizationValidator = new BearerTokenValidator($accessTokenRepositoryMock); $authorizationValidator->setPrivateKeyPath('file://' . __DIR__ . '/../Stubs/private.key'); $authorizationValidator->setPublicKeyPath('file://' . __DIR__ . '/../Stubs/public.key'); @@ -152,10 +150,7 @@ class BearerResponseTypeTest extends \PHPUnit_Framework_TestCase public function testDetermineAccessTokenInHeaderRevokedToken() { - $accessTokenRepositoryMock = $this->getMockBuilder(AccessTokenRepositoryInterface::class)->getMock(); - $accessTokenRepositoryMock->method('isAccessTokenRevoked')->willReturn(true); - - $responseType = new BearerTokenResponse($accessTokenRepositoryMock); + $responseType = new BearerTokenResponse(); $responseType->setPrivateKeyPath('file://' . __DIR__ . '/../Stubs/private.key'); $responseType->setPublicKeyPath('file://' . __DIR__ . '/../Stubs/public.key'); @@ -179,6 +174,9 @@ class BearerResponseTypeTest extends \PHPUnit_Framework_TestCase $response = $responseType->generateHttpResponse(new Response()); $json = json_decode((string) $response->getBody()); + $accessTokenRepositoryMock = $this->getMockBuilder(AccessTokenRepositoryInterface::class)->getMock(); + $accessTokenRepositoryMock->method('isAccessTokenRevoked')->willReturn(true); + $authorizationValidator = new BearerTokenValidator($accessTokenRepositoryMock); $authorizationValidator->setPrivateKeyPath('file://' . __DIR__ . '/../Stubs/private.key'); $authorizationValidator->setPublicKeyPath('file://' . __DIR__ . '/../Stubs/public.key'); @@ -198,12 +196,12 @@ class BearerResponseTypeTest extends \PHPUnit_Framework_TestCase public function testDetermineAccessTokenInHeaderInvalidToken() { - $accessTokenRepositoryMock = $this->getMockBuilder(AccessTokenRepositoryInterface::class)->getMock(); - - $responseType = new BearerTokenResponse($accessTokenRepositoryMock); + $responseType = new BearerTokenResponse(); $responseType->setPrivateKeyPath('file://' . __DIR__ . '/../Stubs/private.key'); $responseType->setPublicKeyPath('file://' . __DIR__ . '/../Stubs/public.key'); + $accessTokenRepositoryMock = $this->getMockBuilder(AccessTokenRepositoryInterface::class)->getMock(); + $authorizationValidator = new BearerTokenValidator($accessTokenRepositoryMock); $authorizationValidator->setPrivateKeyPath('file://' . __DIR__ . '/../Stubs/private.key'); $authorizationValidator->setPublicKeyPath('file://' . __DIR__ . '/../Stubs/public.key');