diff --git a/src/Exception/InvalidClientException.php b/src/Exception/InvalidClientException.php index c09b70b5..ba01d277 100644 --- a/src/Exception/InvalidClientException.php +++ b/src/Exception/InvalidClientException.php @@ -29,7 +29,7 @@ class InvalidClientException extends OAuthException /** * {@inheritdoc} */ - public function __construct($parameter) + public function __construct() { parent::__construct('Client authentication failed.'); } diff --git a/src/Exception/InvalidCredentialsException.php b/src/Exception/InvalidCredentialsException.php index 0aae7431..40c4ce7e 100644 --- a/src/Exception/InvalidCredentialsException.php +++ b/src/Exception/InvalidCredentialsException.php @@ -29,8 +29,8 @@ class InvalidCredentialsException extends OAuthException /** * {@inheritdoc} */ - public function __construct($parameter) + public function __construct() { - parent::__construct('The user credentials were incorrect..'); + parent::__construct('The user credentials were incorrect.'); } } diff --git a/src/Exception/InvalidRefreshException.php b/src/Exception/InvalidRefreshException.php index c1fd1bd5..5c116f84 100644 --- a/src/Exception/InvalidRefreshException.php +++ b/src/Exception/InvalidRefreshException.php @@ -29,7 +29,7 @@ class InvalidRefreshException extends OAuthException /** * {@inheritdoc} */ - public function __construct($parameter) + public function __construct() { parent::__construct('The refresh token is invalid.'); } diff --git a/src/Grant/AuthCode.php b/src/Grant/AuthCode.php index b374b07e..b0980a72 100644 --- a/src/Grant/AuthCode.php +++ b/src/Grant/AuthCode.php @@ -101,7 +101,7 @@ class AuthCode extends AbstractGrant // Ensure response type is one that is recognised if ( ! in_array($responseType, $this->server->getResponseTypes())) { - throw new Exception\UnsupportedResponseTypeException(); + throw new Exception\UnsupportedResponseTypeException($responseType); } // Validate client ID and redirect URI diff --git a/src/Grant/ClientCredentials.php b/src/Grant/ClientCredentials.php index 655fafac..2c4e38d9 100644 --- a/src/Grant/ClientCredentials.php +++ b/src/Grant/ClientCredentials.php @@ -16,7 +16,7 @@ use League\OAuth2\Server\Entity\AccessToken; use League\OAuth2\Server\Entity\Client; use League\OAuth2\Server\Entity\Session; use League\OAuth2\Server\Entity\Scope; -use League\OAuth2\Server\Exception\ClientException; +use League\OAuth2\Server\Exception; use League\OAuth2\Server\Util\SecureKey; use League\OAuth2\Server\Storage\SessionInterface; use League\OAuth2\Server\Storage\ClientInterface; @@ -61,18 +61,12 @@ class ClientCredentials extends AbstractGrant // Get the required params $clientId = $this->server->getRequest()->request->get('client_id', null); if (is_null($clientId)) { - throw new ClientException( - sprintf(AuthorizationServer::getExceptionMessage('invalid_request'), 'client_id'), - 0 - ); + throw new Exception\InvalidRequestException('client_id'); } $clientSecret = $this->server->getRequest()->request->get('client_secret', null); if (is_null($clientSecret)) { - throw new ClientException( - sprintf(AuthorizationServer::getExceptionMessage('invalid_request'), 'client_secret'), - 0 - ); + throw new Exception\InvalidRequestException('client_secret'); } // Validate client ID and client secret @@ -84,7 +78,7 @@ class ClientCredentials extends AbstractGrant ); if (($client instanceof Client) === false) { - throw new ClientException(AuthorizationServer::getExceptionMessage('invalid_client'), 8); + throw new Exception\InvalidClientException(); } // Validate any scopes that are in the request diff --git a/src/Grant/Password.php b/src/Grant/Password.php index 7dcc083c..baaff116 100644 --- a/src/Grant/Password.php +++ b/src/Grant/Password.php @@ -17,8 +17,7 @@ use League\OAuth2\Server\Entity\Client; use League\OAuth2\Server\Entity\RefreshToken as RT; use League\OAuth2\Server\Entity\Session; use League\OAuth2\Server\Entity\Scope; -use League\OAuth2\Server\Exception\ClientException; -use League\OAuth2\Server\Exception\InvalidGrantTypeException; +use League\OAuth2\Server\Exception; use League\OAuth2\Server\Util\SecureKey; use League\OAuth2\Server\Storage\SessionInterface; use League\OAuth2\Server\Storage\ClientInterface; @@ -70,7 +69,7 @@ class Password extends AbstractGrant protected function getVerifyCredentialsCallback() { if (is_null($this->callback) || ! is_callable($this->callback)) { - throw new InvalidGrantTypeException('Null or non-callable callback set on Password grant'); + throw new Exception\ServerErrorException('Null or non-callable callback set on Password grant'); } return $this->callback; @@ -86,18 +85,12 @@ class Password extends AbstractGrant // Get the required params $clientId = $this->server->getRequest()->request->get('client_id', null); if (is_null($clientId)) { - throw new ClientException( - sprintf(AuthorizationServer::getExceptionMessage('invalid_request'), 'client_id'), - 0 - ); + throw new Exception\InvalidRequestException('client_id'); } $clientSecret = $this->server->getRequest()->request->get('client_secret', null); if (is_null($clientSecret)) { - throw new ClientException( - sprintf(AuthorizationServer::getExceptionMessage('invalid_request'), 'client_secret'), - 0 - ); + throw new Exception\InvalidRequestException('client_secret'); } // Validate client ID and client secret @@ -109,30 +102,24 @@ class Password extends AbstractGrant ); if (($client instanceof Client) === false) { - throw new ClientException(AuthorizationServer::getExceptionMessage('invalid_client'), 8); + throw new Exception\InvalidClientException(); } $username = $this->server->getRequest()->request->get('username', null); if (is_null($username)) { - throw new ClientException( - sprintf(AuthorizationServer::getExceptionMessage('invalid_request'), 'username'), - 0 - ); + throw new Exception\InvalidRequestException('username'); } $password = $this->server->getRequest()->request->get('password', null); if (is_null($password)) { - throw new ClientException( - sprintf(AuthorizationServer::getExceptionMessage('invalid_request'), 'password'), - 0 - ); + throw new Exception\InvalidRequestException('password'); } // Check if user's username and password are correct $userId = call_user_func($this->getVerifyCredentialsCallback(), $username, $password); if ($userId === false) { - throw new ClientException($this->server->getExceptionMessage('invalid_credentials'), 0); + throw new Exception\InvalidCredentialsException(); } // Validate any scopes that are in the request diff --git a/src/Grant/RefreshToken.php b/src/Grant/RefreshToken.php index b1993161..80e514f4 100644 --- a/src/Grant/RefreshToken.php +++ b/src/Grant/RefreshToken.php @@ -21,7 +21,6 @@ use League\OAuth2\Server\Storage\ScopeInterface; use League\OAuth2\Server\Entity\RefreshToken as RT; use League\OAuth2\Server\Entity\AccessToken; use League\OAuth2\Server\Entity\Session; -use League\OAuth2\Server\Exception\ClientException; /** * Referesh token grant @@ -65,18 +64,12 @@ class RefreshToken extends AbstractGrant { $clientId = $this->server->getRequest()->request->get('client_id', null); if (is_null($clientId)) { - throw new Exception\ClientException( - sprintf($this->server->getExceptionMessage('invalid_request'), 'client_id'), - 0 - ); + throw new Exception\InvalidRequestException('client_id'); } $clientSecret = $this->server->getRequest()->request->get('client_secret', null); if (is_null($clientSecret)) { - throw new Exception\ClientException( - sprintf($this->server->getExceptionMessage('invalid_request'), 'client_secret'), - 0 - ); + throw new Exception\InvalidRequestException('client_secret'); } // Validate client ID and client secret @@ -88,22 +81,19 @@ class RefreshToken extends AbstractGrant ); if ($client === null) { - throw new ClientException(AuthorizationServer::getExceptionMessage('invalid_client'), 8); + throw new Exception\InvalidClientException(); } $oldRefreshTokenParam = $this->server->getRequest()->request->get('refresh_token', null); if ($oldRefreshTokenParam === null) { - throw new Exception\ClientException( - sprintf($this->server->getExceptionMessage('invalid_request'), 'refresh_token'), - 0 - ); + throw new Exception\InvalidRequestException('refresh_token'); } // Validate refresh token $oldRefreshToken = $this->server->getStorage('refresh_token')->get($oldRefreshTokenParam); if (($oldRefreshToken instanceof RT) === false) { - throw new Exception\ClientException($this->server->getExceptionMessage('invalid_refresh'), 0); + throw new Exception\InvalidRefreshException(); } $oldAccessToken = $oldRefreshToken->getAccessToken(); @@ -124,10 +114,7 @@ class RefreshToken extends AbstractGrant // the request doesn't include any new scopes foreach ($requestedScopes as $requestedScope) { if (!isset($scopes[$requestedScope->getId()])) { - throw new Exception\ClientException( - sprintf($this->server->getExceptionMessage('invalid_scope'), $requestedScope->getId()), - 0 - ); + throw new Exception\InvalidScopeException($requestedScope->getId()); } } diff --git a/src/ResourceServer.php b/src/ResourceServer.php index 35ed1e37..f3723dbf 100644 --- a/src/ResourceServer.php +++ b/src/ResourceServer.php @@ -210,7 +210,7 @@ class ResourceServer extends AbstractServer } if (empty($accessToken)) { - throw new Exception\InvalidAccessTokenException('Access token is missing'); + throw new Exception\InvalidRequestException('access token'); } return $accessToken;