Skip to content

Commit

Permalink
Merge pull request #970 from Sephster/interface-revert
Browse files Browse the repository at this point in the history
Revert Interface Change
  • Loading branch information
Sephster authored Nov 15, 2018
2 parents a61c6a3 + 7839a61 commit f2cd364
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 23 deletions.
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [Unreleased]

## [7.3.1] - released 2018-11-15

### Fixed
- Fix issue with previous release where interface had changed for the AuthorizationServer. Reverted to the previous interface while maintaining functionality changes (PR #970)

## [7.3.0] - released 2018-11-13

### Changed
Expand Down Expand Up @@ -422,7 +427,8 @@ Version 5 is a complete code rewrite.

- First major release

[Unreleased]: https://github.com/thephpleague/oauth2-server/compare/7.3.0...HEAD
[Unreleased]: https://github.com/thephpleague/oauth2-server/compare/7.3.1...HEAD
[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
[7.1.1]: https://github.com/thephpleague/oauth2-server/compare/7.1.0...7.1.1
Expand Down
26 changes: 13 additions & 13 deletions src/AuthorizationServer.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class AuthorizationServer implements EmitterAwareInterface
/**
* @var ResponseTypeInterface
*/
protected $responseTypePrototype;
protected $responseType;

/**
* @var ClientRepositoryInterface
Expand Down Expand Up @@ -87,15 +87,15 @@ class AuthorizationServer implements EmitterAwareInterface
* @param ScopeRepositoryInterface $scopeRepository
* @param CryptKey|string $privateKey
* @param string|Key $encryptionKey
* @param null|ResponseTypeInterface $responseTypePrototype
* @param null|ResponseTypeInterface $responseType
*/
public function __construct(
ClientRepositoryInterface $clientRepository,
AccessTokenRepositoryInterface $accessTokenRepository,
ScopeRepositoryInterface $scopeRepository,
$privateKey,
$encryptionKey,
ResponseTypeInterface $responseTypePrototype = null
ResponseTypeInterface $responseType = null
) {
$this->clientRepository = $clientRepository;
$this->accessTokenRepository = $accessTokenRepository;
Expand All @@ -108,19 +108,19 @@ public function __construct(
$this->privateKey = $privateKey;
$this->encryptionKey = $encryptionKey;

if ($responseTypePrototype === null) {
$responseTypePrototype = new BearerTokenResponse();
if ($responseType === null) {
$responseType = new BearerTokenResponse();
} else {
$responseTypePrototype = clone $responseTypePrototype;
$responseType = clone $responseType;
}

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

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

$this->responseTypePrototype = $responseTypePrototype;
$this->responseType = $responseType;
}

/**
Expand Down Expand Up @@ -200,7 +200,7 @@ public function respondToAccessTokenRequest(ServerRequestInterface $request, Res
}
$tokenResponse = $grantType->respondToAccessTokenRequest(
$request,
$this->newResponseType(),
$this->getResponseType(),
$this->grantTypeAccessTokenTTL[$grantType->getIdentifier()]
);

Expand All @@ -217,9 +217,9 @@ public function respondToAccessTokenRequest(ServerRequestInterface $request, Res
*
* @return ResponseTypeInterface
*/
protected function newResponseType()
protected function getResponseType()
{
return clone $this->responseTypePrototype;
return clone $this->responseType;
}

/**
Expand Down
14 changes: 5 additions & 9 deletions tests/AuthorizationServerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public function testRespondToRequest()
$this->assertEquals(200, $response->getStatusCode());
}

public function testNewDefaultResponseType()
public function testGetResponseType()
{
$clientRepository = $this->getMockBuilder(ClientRepositoryInterface::class)->getMock();

Expand All @@ -104,17 +104,13 @@ public function testNewDefaultResponseType()
);

$abstractGrantReflection = new \ReflectionClass($server);
$method = $abstractGrantReflection->getMethod('newResponseType');
$method = $abstractGrantReflection->getMethod('getResponseType');
$method->setAccessible(true);

$responseTypeA = $method->invoke($server);
$responseTypeB = $method->invoke($server);
$this->assertInstanceOf(BearerTokenResponse::class, $responseTypeA);
$this->assertInstanceOf(BearerTokenResponse::class, $responseTypeB);
$this->assertNotSame($responseTypeA, $responseTypeB);
$this->assertInstanceOf(BearerTokenResponse::class, $method->invoke($server));
}

public function testNewResponseTypeFromPrototype()
public function testMultipleRequestsGetDifferentResponseTypeInstances()
{
$privateKey = 'file://' . __DIR__ . '/Stubs/private.key';
$encryptionKey = 'file://' . __DIR__ . '/Stubs/public.key';
Expand Down Expand Up @@ -144,7 +140,7 @@ public function getEncryptionKey()
);

$abstractGrantReflection = new \ReflectionClass($server);
$method = $abstractGrantReflection->getMethod('newResponseType');
$method = $abstractGrantReflection->getMethod('getResponseType');
$method->setAccessible(true);

$responseTypeA = $method->invoke($server);
Expand Down

0 comments on commit f2cd364

Please sign in to comment.