Skip to content

Commit

Permalink
Merge pull request #969 from ceeram/fix-bc-break
Browse files Browse the repository at this point in the history
Fix bc breaking change
  • Loading branch information
Sephster authored Nov 21, 2018
2 parents f2cd364 + 46493c4 commit 9783388
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 8 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
16 changes: 9 additions & 7 deletions src/AuthorizationServer.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,6 @@ public function __construct(
$responseType = clone $responseType;
}

if ($responseType instanceof AbstractResponseType) {
$responseType->setPrivateKey($this->privateKey);
}

$responseType->setEncryptionKey($this->encryptionKey);

$this->responseType = $responseType;
}

Expand Down Expand Up @@ -219,7 +213,15 @@ public function respondToAccessTokenRequest(ServerRequestInterface $request, Res
*/
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;
}

/**
Expand Down
37 changes: 37 additions & 0 deletions tests/AuthorizationServerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,43 @@ public function testGetResponseType()
$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';
Expand Down

0 comments on commit 9783388

Please sign in to comment.