mirror of
https://github.com/elyby/oauth2-server.git
synced 2025-01-03 18:51:53 +05:30
Merge pull request #459 from juliangut/throw_instead_of_return
V5 - Throw exception instead of return Response
This commit is contained in:
commit
c3ffed2daf
@ -128,7 +128,8 @@ class Server implements EmitterAwareInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
$tokenResponse = null;
|
$tokenResponse = null;
|
||||||
foreach ($this->enabledGrantTypes as $grantType) {
|
while ($tokenResponse === null && $grantType = array_shift($this->enabledGrantTypes)) {
|
||||||
|
/** @var \League\OAuth2\Server\Grant\GrantTypeInterface $grantType */
|
||||||
if ($grantType->canRespondToRequest($request)) {
|
if ($grantType->canRespondToRequest($request)) {
|
||||||
$tokenResponse = $grantType->respondToRequest(
|
$tokenResponse = $grantType->respondToRequest(
|
||||||
$request,
|
$request,
|
||||||
@ -142,11 +143,11 @@ class Server implements EmitterAwareInterface
|
|||||||
return $tokenResponse;
|
return $tokenResponse;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($tokenResponse instanceof ResponseTypeInterface === false) {
|
if ($tokenResponse instanceof ResponseTypeInterface) {
|
||||||
return OAuthServerException::unsupportedGrantType()->generateHttpResponse($response);
|
return $tokenResponse->generateHttpResponse($response);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $tokenResponse->generateHttpResponse($response);
|
throw OAuthServerException::unsupportedGrantType();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -33,9 +33,12 @@ class ServerTest extends \PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
$server->enableGrantType(new ClientCredentialsGrant(), new \DateInterval('PT1M'));
|
$server->enableGrantType(new ClientCredentialsGrant(), new \DateInterval('PT1M'));
|
||||||
|
|
||||||
$response = $server->respondToRequest();
|
try {
|
||||||
$this->assertTrue($response instanceof ResponseInterface);
|
$server->respondToRequest();
|
||||||
$this->assertEquals(400, $response->getStatusCode());
|
} catch (OAuthServerException $e) {
|
||||||
|
$this->assertEquals('unsupported_grant_type', $e->getErrorType());
|
||||||
|
$this->assertEquals(400, $e->getHttpStatusCode());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testRespondToRequest()
|
public function testRespondToRequest()
|
||||||
|
Loading…
Reference in New Issue
Block a user