mirror of
https://github.com/elyby/oauth2-server.git
synced 2024-11-01 16:33:07 +05:30
Updates to exceptions
This commit is contained in:
parent
6981ced972
commit
9f1f0cc3bc
@ -29,7 +29,7 @@ class InvalidClientException extends OAuthException
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function __construct($parameter)
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct('Client authentication failed.');
|
||||
}
|
||||
|
@ -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.');
|
||||
}
|
||||
}
|
||||
|
@ -29,7 +29,7 @@ class InvalidRefreshException extends OAuthException
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function __construct($parameter)
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct('The refresh token is invalid.');
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user