From 3eabbafe5b2a771dc445ef35f4a0206e4a932557 Mon Sep 17 00:00:00 2001 From: sephster Date: Sat, 1 Sep 2018 14:53:27 +0100 Subject: [PATCH] Client says if it is confidential instead of repository --- src/Grant/AuthCodeGrant.php | 11 +++-------- src/Repositories/ClientRepositoryInterface.php | 9 --------- tests/Grant/AuthCodeGrantTest.php | 16 ---------------- 3 files changed, 3 insertions(+), 33 deletions(-) diff --git a/src/Grant/AuthCodeGrant.php b/src/Grant/AuthCodeGrant.php index a4360bae..378f2096 100644 --- a/src/Grant/AuthCodeGrant.php +++ b/src/Grant/AuthCodeGrant.php @@ -79,16 +79,11 @@ class AuthCodeGrant extends AbstractAuthorizeGrant throw OAuthServerException::invalidRequest('client_id'); } + $client = $this->clientRepository->getClientEntity($clientId); + // Only validate the client if it is confidential - if ($this->clientRepository->isClientConfidential($clientId)) { + if ($client->isConfidential()) { $client = $this->validateClient($request); - } else { - $client = $this->clientRepository->getClientEntity( - $clientId, - $this->getIdentifier(), - null, - false - ); } $encryptedAuthCode = $this->getRequestParameter('code', $request, null); diff --git a/src/Repositories/ClientRepositoryInterface.php b/src/Repositories/ClientRepositoryInterface.php index eee03104..47b6083a 100644 --- a/src/Repositories/ClientRepositoryInterface.php +++ b/src/Repositories/ClientRepositoryInterface.php @@ -25,15 +25,6 @@ interface ClientRepositoryInterface extends RepositoryInterface */ public function getClientEntity($clientIdentifier); - /** - * Check if a client is confidential. - * - * @param string $clientIdentifier The client's identifier - * - * @return bool - */ - public function isClientConfidential($clientIdentifier); - /** * Validate a client's secret. * diff --git a/tests/Grant/AuthCodeGrantTest.php b/tests/Grant/AuthCodeGrantTest.php index a415f3e1..49c6e722 100644 --- a/tests/Grant/AuthCodeGrantTest.php +++ b/tests/Grant/AuthCodeGrantTest.php @@ -546,7 +546,6 @@ class AuthCodeGrantTest extends TestCase $client->isConfidential(); $clientRepositoryMock = $this->getMockBuilder(ClientRepositoryInterface::class)->getMock(); $clientRepositoryMock->method('getClientEntity')->willReturn($client); - $clientRepositoryMock->method('isClientConfidential')->willReturn(true); $scopeRepositoryMock = $this->getMockBuilder(ScopeRepositoryInterface::class)->getMock(); $scopeEntity = new ScopeEntity(); @@ -615,7 +614,6 @@ class AuthCodeGrantTest extends TestCase $client->setRedirectUri('http://foo/bar'); $clientRepositoryMock = $this->getMockBuilder(ClientRepositoryInterface::class)->getMock(); $clientRepositoryMock->method('getClientEntity')->willReturn($client); - $clientRepositoryMock->method('isClientConfidential')->willReturn(false); $scopeRepositoryMock = $this->getMockBuilder(ScopeRepositoryInterface::class)->getMock(); $scopeEntity = new ScopeEntity(); @@ -686,7 +684,6 @@ class AuthCodeGrantTest extends TestCase $client->isConfidential(); $clientRepositoryMock = $this->getMockBuilder(ClientRepositoryInterface::class)->getMock(); $clientRepositoryMock->method('getClientEntity')->willReturn($client); - $clientRepositoryMock->method('isClientConfidential')->willReturn(true); $scopeRepositoryMock = $this->getMockBuilder(ScopeRepositoryInterface::class)->getMock(); $scopeEntity = new ScopeEntity(); @@ -760,7 +757,6 @@ class AuthCodeGrantTest extends TestCase $client->isConfidential(); $clientRepositoryMock = $this->getMockBuilder(ClientRepositoryInterface::class)->getMock(); $clientRepositoryMock->method('getClientEntity')->willReturn($client); - $clientRepositoryMock->method('isClientConfidential')->willReturn(true); $scopeRepositoryMock = $this->getMockBuilder(ScopeRepositoryInterface::class)->getMock(); $scopeEntity = new ScopeEntity(); @@ -837,7 +833,6 @@ class AuthCodeGrantTest extends TestCase $client->isConfidential(); $clientRepositoryMock = $this->getMockBuilder(ClientRepositoryInterface::class)->getMock(); $clientRepositoryMock->method('getClientEntity')->willReturn($client); - $clientRepositoryMock->method('isClientConfidential')->willReturn(true); $grant = new AuthCodeGrant( $this->getMockBuilder(AuthCodeRepositoryInterface::class)->getMock(), @@ -886,7 +881,6 @@ class AuthCodeGrantTest extends TestCase $client->isConfidential(); $clientRepositoryMock = $this->getMockBuilder(ClientRepositoryInterface::class)->getMock(); $clientRepositoryMock->method('getClientEntity')->willReturn($client); - $clientRepositoryMock->method('isClientConfidential')->willReturn(true); $grant = new AuthCodeGrant( $this->getMockBuilder(AuthCodeRepositoryInterface::class)->getMock(), @@ -936,7 +930,6 @@ class AuthCodeGrantTest extends TestCase $client->isConfidential(); $clientRepositoryMock = $this->getMockBuilder(ClientRepositoryInterface::class)->getMock(); $clientRepositoryMock->method('getClientEntity')->willReturn($client); - $clientRepositoryMock->method('isClientConfidential')->willReturn(true); $accessTokenRepositoryMock = $this->getMockBuilder(AccessTokenRepositoryInterface::class)->getMock(); $refreshTokenRepositoryMock = $this->getMockBuilder(RefreshTokenRepositoryInterface::class)->getMock(); @@ -980,7 +973,6 @@ class AuthCodeGrantTest extends TestCase $client->isConfidential(); $clientRepositoryMock = $this->getMockBuilder(ClientRepositoryInterface::class)->getMock(); $clientRepositoryMock->method('getClientEntity')->willReturn($client); - $clientRepositoryMock->method('isClientConfidential')->willReturn(true); $accessTokenRepositoryMock = $this->getMockBuilder(AccessTokenRepositoryInterface::class)->getMock(); $accessTokenRepositoryMock->method('persistNewAccessToken')->willReturnSelf(); @@ -1042,7 +1034,6 @@ class AuthCodeGrantTest extends TestCase $client->isConfidential(); $clientRepositoryMock = $this->getMockBuilder(ClientRepositoryInterface::class)->getMock(); $clientRepositoryMock->method('getClientEntity')->willReturn($client); - $clientRepositoryMock->method('isClientConfidential')->willReturn(true); $accessTokenRepositoryMock = $this->getMockBuilder(AccessTokenRepositoryInterface::class)->getMock(); $accessTokenRepositoryMock->method('persistNewAccessToken')->willReturnSelf(); @@ -1107,7 +1098,6 @@ class AuthCodeGrantTest extends TestCase $client->isConfidential(); $clientRepositoryMock = $this->getMockBuilder(ClientRepositoryInterface::class)->getMock(); $clientRepositoryMock->method('getClientEntity')->willReturn($client); - $clientRepositoryMock->method('isClientConfidential')->willReturn(true); $accessTokenRepositoryMock = $this->getMockBuilder(AccessTokenRepositoryInterface::class)->getMock(); $accessTokenRepositoryMock->method('persistNewAccessToken')->willReturnSelf(); @@ -1169,7 +1159,6 @@ class AuthCodeGrantTest extends TestCase $client->isConfidential(); $clientRepositoryMock = $this->getMockBuilder(ClientRepositoryInterface::class)->getMock(); $clientRepositoryMock->method('getClientEntity')->willReturn($client); - $clientRepositoryMock->method('isClientConfidential')->willReturn(true); $accessTokenRepositoryMock = $this->getMockBuilder(AccessTokenRepositoryInterface::class)->getMock(); $accessTokenRepositoryMock->method('persistNewAccessToken')->willReturnSelf(); @@ -1220,7 +1209,6 @@ class AuthCodeGrantTest extends TestCase $client->isConfidential(); $clientRepositoryMock = $this->getMockBuilder(ClientRepositoryInterface::class)->getMock(); $clientRepositoryMock->method('getClientEntity')->willReturn($client); - $clientRepositoryMock->method('isClientConfidential')->willReturn(true); $scopeRepositoryMock = $this->getMockBuilder(ScopeRepositoryInterface::class)->getMock(); $scopeEntity = new ScopeEntity(); @@ -1294,7 +1282,6 @@ class AuthCodeGrantTest extends TestCase $client->isConfidential(); $clientRepositoryMock = $this->getMockBuilder(ClientRepositoryInterface::class)->getMock(); $clientRepositoryMock->method('getClientEntity')->willReturn($client); - $clientRepositoryMock->method('isClientConfidential')->willReturn(true); $scopeRepositoryMock = $this->getMockBuilder(ScopeRepositoryInterface::class)->getMock(); $scopeEntity = new ScopeEntity(); @@ -1368,7 +1355,6 @@ class AuthCodeGrantTest extends TestCase $client->isConfidential(); $clientRepositoryMock = $this->getMockBuilder(ClientRepositoryInterface::class)->getMock(); $clientRepositoryMock->method('getClientEntity')->willReturn($client); - $clientRepositoryMock->method('isClientConfidential')->willReturn(true); $scopeRepositoryMock = $this->getMockBuilder(ScopeRepositoryInterface::class)->getMock(); $scopeEntity = new ScopeEntity(); @@ -1442,7 +1428,6 @@ class AuthCodeGrantTest extends TestCase $client->isConfidential(); $clientRepositoryMock = $this->getMockBuilder(ClientRepositoryInterface::class)->getMock(); $clientRepositoryMock->method('getClientEntity')->willReturn($client); - $clientRepositoryMock->method('isClientConfidential')->willReturn(true); $scopeRepositoryMock = $this->getMockBuilder(ScopeRepositoryInterface::class)->getMock(); $scopeEntity = new ScopeEntity(); @@ -1516,7 +1501,6 @@ class AuthCodeGrantTest extends TestCase $client->isConfidential(); $clientRepositoryMock = $this->getMockBuilder(ClientRepositoryInterface::class)->getMock(); $clientRepositoryMock->method('getClientEntity')->willReturn($client); - $clientRepositoryMock->method('isClientConfidential')->willReturn(true); $scopeRepositoryMock = $this->getMockBuilder(ScopeRepositoryInterface::class)->getMock(); $scopeEntity = new ScopeEntity();