From cdf43e498e3ede1d96d959c87c02c4a9d423a9f9 Mon Sep 17 00:00:00 2001 From: Alex Bilbie Date: Wed, 4 May 2016 08:55:57 +0100 Subject: [PATCH] Use constant for event name instead of explicit string. Fixes #563 --- src/Grant/AbstractGrant.php | 11 +++-------- src/Grant/AuthCodeGrant.php | 6 +++--- src/Grant/ImplicitGrant.php | 6 +++--- src/Grant/PasswordGrant.php | 2 +- src/Grant/RefreshTokenGrant.php | 2 +- src/RequestEvent.php | 4 ++++ 6 files changed, 15 insertions(+), 16 deletions(-) diff --git a/src/Grant/AbstractGrant.php b/src/Grant/AbstractGrant.php index cdbd04ff..45c8fc2a 100644 --- a/src/Grant/AbstractGrant.php +++ b/src/Grant/AbstractGrant.php @@ -35,11 +35,6 @@ abstract class AbstractGrant implements GrantTypeInterface const SCOPE_DELIMITER_STRING = ' '; - /** - * @var ServerRequestInterface - */ - protected $request; - /** * @var ClientRepositoryInterface */ @@ -166,7 +161,7 @@ abstract class AbstractGrant implements GrantTypeInterface ); 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(); } @@ -177,13 +172,13 @@ abstract class AbstractGrant implements GrantTypeInterface is_string($client->getRedirectUri()) && (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(); } elseif ( is_array($client->getRedirectUri()) && 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(); } } diff --git a/src/Grant/AuthCodeGrant.php b/src/Grant/AuthCodeGrant.php index b9416a2b..9216e167 100644 --- a/src/Grant/AuthCodeGrant.php +++ b/src/Grant/AuthCodeGrant.php @@ -176,7 +176,7 @@ class AuthCodeGrant extends AbstractAuthorizeGrant ); 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(); } @@ -186,13 +186,13 @@ class AuthCodeGrant extends AbstractAuthorizeGrant is_string($client->getRedirectUri()) && (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(); } elseif ( is_array($client->getRedirectUri()) && 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(); } } diff --git a/src/Grant/ImplicitGrant.php b/src/Grant/ImplicitGrant.php index f3a74ced..0bd33fa6 100644 --- a/src/Grant/ImplicitGrant.php +++ b/src/Grant/ImplicitGrant.php @@ -123,7 +123,7 @@ class ImplicitGrant extends AbstractAuthorizeGrant ); 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(); } @@ -133,13 +133,13 @@ class ImplicitGrant extends AbstractAuthorizeGrant is_string($client->getRedirectUri()) && (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(); } elseif ( is_array($client->getRedirectUri()) && 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(); } } diff --git a/src/Grant/PasswordGrant.php b/src/Grant/PasswordGrant.php index f87fc6ea..86ba1e32 100644 --- a/src/Grant/PasswordGrant.php +++ b/src/Grant/PasswordGrant.php @@ -92,7 +92,7 @@ class PasswordGrant extends AbstractGrant $client ); 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(); } diff --git a/src/Grant/RefreshTokenGrant.php b/src/Grant/RefreshTokenGrant.php index 0d65fae6..d4d693a6 100644 --- a/src/Grant/RefreshTokenGrant.php +++ b/src/Grant/RefreshTokenGrant.php @@ -107,7 +107,7 @@ class RefreshTokenGrant extends AbstractGrant $refreshTokenData = json_decode($refreshToken, true); 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'); } diff --git a/src/RequestEvent.php b/src/RequestEvent.php index f6cf4d92..42ce47b2 100644 --- a/src/RequestEvent.php +++ b/src/RequestEvent.php @@ -13,6 +13,10 @@ use Psr\Http\Message\ServerRequestInterface; 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 */