include CryptTrait tests, allow Server::respondToRequest trhow exceptions and fix ResposeType tests

This commit is contained in:
Julián Gutiérrez
2016-03-18 00:25:32 +01:00
parent 8196f5c832
commit 4b775fe241
11 changed files with 200 additions and 186 deletions

View File

@@ -127,27 +127,23 @@ class Server implements EmitterAwareInterface
*/
public function respondToRequest(ServerRequestInterface $request, ResponseInterface $response)
{
try {
$tokenResponse = null;
while ($tokenResponse === null && $grantType = array_shift($this->enabledGrantTypes)) {
/** @var \League\OAuth2\Server\Grant\GrantTypeInterface $grantType */
if ($grantType->canRespondToRequest($request)) {
$tokenResponse = $grantType->respondToRequest(
$request,
$this->getResponseType(),
$this->grantTypeAccessTokenTTL[$grantType->getIdentifier()]
);
}
$tokenResponse = null;
while ($tokenResponse === null && $grantType = array_shift($this->enabledGrantTypes)) {
/** @var \League\OAuth2\Server\Grant\GrantTypeInterface $grantType */
if ($grantType->canRespondToRequest($request)) {
$tokenResponse = $grantType->respondToRequest(
$request,
$this->getResponseType(),
$this->grantTypeAccessTokenTTL[$grantType->getIdentifier()]
);
}
if ($tokenResponse instanceof ResponseTypeInterface) {
return $tokenResponse->generateHttpResponse($response);
}
throw OAuthServerException::unsupportedGrantType();
} catch (OAuthServerException $e) {
return $e->generateHttpResponse($response);
}
if ($tokenResponse instanceof ResponseTypeInterface) {
return $tokenResponse->generateHttpResponse($response);
}
throw OAuthServerException::unsupportedGrantType();
}
/**