From f1454cde3648d96c478155d158568ca0ae1dd900 Mon Sep 17 00:00:00 2001 From: Marc Ypes Date: Thu, 15 Nov 2018 17:21:27 +0100 Subject: [PATCH 1/4] Fix bc breaking change --- src/AuthorizationServer.php | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/AuthorizationServer.php b/src/AuthorizationServer.php index e96ce04f..ce684d1a 100644 --- a/src/AuthorizationServer.php +++ b/src/AuthorizationServer.php @@ -114,12 +114,6 @@ class AuthorizationServer implements EmitterAwareInterface $responseType = clone $responseType; } - if ($responseType instanceof AbstractResponseType) { - $responseType->setPrivateKey($this->privateKey); - } - - $responseType->setEncryptionKey($this->encryptionKey); - $this->responseType = $responseType; } @@ -219,7 +213,14 @@ class AuthorizationServer implements EmitterAwareInterface */ protected function getResponseType() { - return clone $this->responseType; + $responseType = clone $this->responseType; + if ($responseType instanceof AbstractResponseType) { + $responseType->setPrivateKey($this->privateKey); + } + + $responseType->setEncryptionKey($this->encryptionKey); + + return $responseType; } /** From b09154af33025d690bd15f9c5ba788568b1b056a Mon Sep 17 00:00:00 2001 From: Marc Ypes Date: Fri, 16 Nov 2018 12:57:37 +0100 Subject: [PATCH 2/4] Add test to prove bc break --- tests/AuthorizationServerTest.php | 37 +++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/tests/AuthorizationServerTest.php b/tests/AuthorizationServerTest.php index 73f84a61..0a8bf6d1 100644 --- a/tests/AuthorizationServerTest.php +++ b/tests/AuthorizationServerTest.php @@ -110,6 +110,43 @@ class AuthorizationServerTest extends TestCase $this->assertInstanceOf(BearerTokenResponse::class, $method->invoke($server)); } + public function testGetResponseTypeExtended() + { + $clientRepository = $this->getMockBuilder(ClientRepositoryInterface::class)->getMock(); + $privateKey = 'file://' . __DIR__ . '/Stubs/private.key'; + $encryptionKey = 'file://' . __DIR__ . '/Stubs/public.key'; + + $server = new class($clientRepository, $this->getMockBuilder(AccessTokenRepositoryInterface::class)->getMock(), $this->getMockBuilder(ScopeRepositoryInterface::class)->getMock(), $privateKey, $encryptionKey) extends AuthorizationServer { + protected function getResponseType() + { + $this->responseType = new class extends BearerTokenResponse { + /* @return null|CryptKey */ + public function getPrivateKey() + { + return $this->privateKey; + } + + public function getEncryptionKey() + { + return $this->encryptionKey; + } + }; + + return parent::getResponseType(); + } + }; + + $abstractGrantReflection = new \ReflectionClass($server); + $method = $abstractGrantReflection->getMethod('getResponseType'); + $method->setAccessible(true); + $responseType = $method->invoke($server); + + $this->assertInstanceOf(BearerTokenResponse::class, $responseType); + // generated instances should have keys setup + $this->assertSame($privateKey, $responseType->getPrivateKey()->getKeyPath()); + $this->assertSame($encryptionKey, $responseType->getEncryptionKey()); + } + public function testMultipleRequestsGetDifferentResponseTypeInstances() { $privateKey = 'file://' . __DIR__ . '/Stubs/private.key'; From 8b421818f2a7f00224a94f2fe67f0c86ac15268b Mon Sep 17 00:00:00 2001 From: sephster Date: Wed, 21 Nov 2018 21:26:54 +0000 Subject: [PATCH 3/4] Add blank line to better format --- src/AuthorizationServer.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/AuthorizationServer.php b/src/AuthorizationServer.php index ce684d1a..bde97d6e 100644 --- a/src/AuthorizationServer.php +++ b/src/AuthorizationServer.php @@ -214,6 +214,7 @@ class AuthorizationServer implements EmitterAwareInterface protected function getResponseType() { $responseType = clone $this->responseType; + if ($responseType instanceof AbstractResponseType) { $responseType->setPrivateKey($this->privateKey); } From 46493c461e00ee1a941c1f6baac4ce4be88403bb Mon Sep 17 00:00:00 2001 From: sephster Date: Wed, 21 Nov 2018 21:29:55 +0000 Subject: [PATCH 4/4] Update changelog for 7.3.2 release --- CHANGELOG.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bceb11f6..f511374a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ## [Unreleased] +## [7.3.2] - released 2018-11-21 + +- Revert setting keys on response type to be inside `getResponseType()` function instead of AuthorizationServer constructor (PR #969) + ## [7.3.1] - released 2018-11-15 ### Fixed @@ -427,7 +431,8 @@ Version 5 is a complete code rewrite. - First major release -[Unreleased]: https://github.com/thephpleague/oauth2-server/compare/7.3.1...HEAD +[Unreleased]: https://github.com/thephpleague/oauth2-server/compare/7.3.2...HEAD +[7.3.2]: https://github.com/thephpleague/oauth2-server/compare/7.3.1...7.3.2 [7.3.1]: https://github.com/thephpleague/oauth2-server/compare/7.3.0...7.3.1 [7.3.0]: https://github.com/thephpleague/oauth2-server/compare/7.2.0...7.3.0 [7.2.0]: https://github.com/thephpleague/oauth2-server/compare/7.1.1...7.2.0