Use constant for event name instead of explicit string. Fixes #563

This commit is contained in:
Alex Bilbie 2016-05-04 08:55:57 +01:00
parent acf262f879
commit cdf43e498e
6 changed files with 15 additions and 16 deletions

View File

@ -35,11 +35,6 @@ abstract class AbstractGrant implements GrantTypeInterface
const SCOPE_DELIMITER_STRING = ' '; const SCOPE_DELIMITER_STRING = ' ';
/**
* @var ServerRequestInterface
*/
protected $request;
/** /**
* @var ClientRepositoryInterface * @var ClientRepositoryInterface
*/ */
@ -166,7 +161,7 @@ abstract class AbstractGrant implements GrantTypeInterface
); );
if (!$client instanceof ClientEntityInterface) { if (!$client instanceof ClientEntityInterface) {
$this->getEmitter()->emit(new RequestEvent('client.authentication.failed', $request)); $this->getEmitter()->emit(new RequestEvent(RequestEvent::CLIENT_AUTHENTICATION_FAILED, $request));
throw OAuthServerException::invalidClient(); throw OAuthServerException::invalidClient();
} }
@ -177,13 +172,13 @@ abstract class AbstractGrant implements GrantTypeInterface
is_string($client->getRedirectUri()) is_string($client->getRedirectUri())
&& (strcmp($client->getRedirectUri(), $redirectUri) !== 0) && (strcmp($client->getRedirectUri(), $redirectUri) !== 0)
) { ) {
$this->getEmitter()->emit(new RequestEvent('client.authentication.failed', $request)); $this->getEmitter()->emit(new RequestEvent(RequestEvent::CLIENT_AUTHENTICATION_FAILED, $request));
throw OAuthServerException::invalidClient(); throw OAuthServerException::invalidClient();
} elseif ( } elseif (
is_array($client->getRedirectUri()) is_array($client->getRedirectUri())
&& in_array($redirectUri, $client->getRedirectUri()) === false && in_array($redirectUri, $client->getRedirectUri()) === false
) { ) {
$this->getEmitter()->emit(new RequestEvent('client.authentication.failed', $request)); $this->getEmitter()->emit(new RequestEvent(RequestEvent::CLIENT_AUTHENTICATION_FAILED, $request));
throw OAuthServerException::invalidClient(); throw OAuthServerException::invalidClient();
} }
} }

View File

@ -176,7 +176,7 @@ class AuthCodeGrant extends AbstractAuthorizeGrant
); );
if ($client instanceof ClientEntityInterface === false) { if ($client instanceof ClientEntityInterface === false) {
$this->getEmitter()->emit(new RequestEvent('client.authentication.failed', $request)); $this->getEmitter()->emit(new RequestEvent(RequestEvent::CLIENT_AUTHENTICATION_FAILED, $request));
throw OAuthServerException::invalidClient(); throw OAuthServerException::invalidClient();
} }
@ -186,13 +186,13 @@ class AuthCodeGrant extends AbstractAuthorizeGrant
is_string($client->getRedirectUri()) is_string($client->getRedirectUri())
&& (strcmp($client->getRedirectUri(), $redirectUri) !== 0) && (strcmp($client->getRedirectUri(), $redirectUri) !== 0)
) { ) {
$this->getEmitter()->emit(new RequestEvent('client.authentication.failed', $request)); $this->getEmitter()->emit(new RequestEvent(RequestEvent::CLIENT_AUTHENTICATION_FAILED, $request));
throw OAuthServerException::invalidClient(); throw OAuthServerException::invalidClient();
} elseif ( } elseif (
is_array($client->getRedirectUri()) is_array($client->getRedirectUri())
&& in_array($redirectUri, $client->getRedirectUri()) === false && in_array($redirectUri, $client->getRedirectUri()) === false
) { ) {
$this->getEmitter()->emit(new RequestEvent('client.authentication.failed', $request)); $this->getEmitter()->emit(new RequestEvent(RequestEvent::CLIENT_AUTHENTICATION_FAILED, $request));
throw OAuthServerException::invalidClient(); throw OAuthServerException::invalidClient();
} }
} }

View File

@ -123,7 +123,7 @@ class ImplicitGrant extends AbstractAuthorizeGrant
); );
if ($client instanceof ClientEntityInterface === false) { if ($client instanceof ClientEntityInterface === false) {
$this->getEmitter()->emit(new RequestEvent('client.authentication.failed', $request)); $this->getEmitter()->emit(new RequestEvent(RequestEvent::CLIENT_AUTHENTICATION_FAILED, $request));
throw OAuthServerException::invalidClient(); throw OAuthServerException::invalidClient();
} }
@ -133,13 +133,13 @@ class ImplicitGrant extends AbstractAuthorizeGrant
is_string($client->getRedirectUri()) is_string($client->getRedirectUri())
&& (strcmp($client->getRedirectUri(), $redirectUri) !== 0) && (strcmp($client->getRedirectUri(), $redirectUri) !== 0)
) { ) {
$this->getEmitter()->emit(new RequestEvent('client.authentication.failed', $request)); $this->getEmitter()->emit(new RequestEvent(RequestEvent::CLIENT_AUTHENTICATION_FAILED, $request));
throw OAuthServerException::invalidClient(); throw OAuthServerException::invalidClient();
} elseif ( } elseif (
is_array($client->getRedirectUri()) is_array($client->getRedirectUri())
&& in_array($redirectUri, $client->getRedirectUri()) === false && in_array($redirectUri, $client->getRedirectUri()) === false
) { ) {
$this->getEmitter()->emit(new RequestEvent('client.authentication.failed', $request)); $this->getEmitter()->emit(new RequestEvent(RequestEvent::CLIENT_AUTHENTICATION_FAILED, $request));
throw OAuthServerException::invalidClient(); throw OAuthServerException::invalidClient();
} }
} }

View File

@ -92,7 +92,7 @@ class PasswordGrant extends AbstractGrant
$client $client
); );
if (!$user instanceof UserEntityInterface) { if (!$user instanceof UserEntityInterface) {
$this->getEmitter()->emit(new RequestEvent('user.authentication.failed', $request)); $this->getEmitter()->emit(new RequestEvent(RequestEvent::USER_AUTHENTICATION_FAILED, $request));
throw OAuthServerException::invalidCredentials(); throw OAuthServerException::invalidCredentials();
} }

View File

@ -107,7 +107,7 @@ class RefreshTokenGrant extends AbstractGrant
$refreshTokenData = json_decode($refreshToken, true); $refreshTokenData = json_decode($refreshToken, true);
if ($refreshTokenData['client_id'] !== $clientId) { if ($refreshTokenData['client_id'] !== $clientId) {
$this->getEmitter()->emit(new RequestEvent('refresh_token.client.failed', $request)); $this->getEmitter()->emit(new RequestEvent(RequestEvent::REFRESH_TOKEN_CLIENT_FAILED, $request));
throw OAuthServerException::invalidRefreshToken('Token is not linked to client'); throw OAuthServerException::invalidRefreshToken('Token is not linked to client');
} }

View File

@ -13,6 +13,10 @@ use Psr\Http\Message\ServerRequestInterface;
class RequestEvent extends Event class RequestEvent extends Event
{ {
const CLIENT_AUTHENTICATION_FAILED = 'client.authentication.failed';
const USER_AUTHENTICATION_FAILED = 'user.authentication.failed';
const REFRESH_TOKEN_CLIENT_FAILED = 'refresh_token.client.failed';
/** /**
* @var \Psr\Http\Message\ServerRequestInterface * @var \Psr\Http\Message\ServerRequestInterface
*/ */