mirror of
https://github.com/elyby/oauth2-server.git
synced 2025-01-21 02:52:43 +05:30
Updated thrown exceptions
This commit is contained in:
parent
019dfa8836
commit
6981ced972
@ -13,7 +13,7 @@ namespace League\OAuth2\Server\Grant;
|
|||||||
|
|
||||||
use League\OAuth2\Server\AuthorizationServer;
|
use League\OAuth2\Server\AuthorizationServer;
|
||||||
use League\OAuth2\Server\Entity\Scope;
|
use League\OAuth2\Server\Entity\Scope;
|
||||||
use League\OAuth2\Server\Exception\ClientException;
|
use League\OAuth2\Server\Exception;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Abstract grant class
|
* Abstract grant class
|
||||||
@ -121,7 +121,7 @@ abstract class AbstractGrant implements GrantTypeInterface
|
|||||||
$this->server->getDefaultScope() === null &&
|
$this->server->getDefaultScope() === null &&
|
||||||
count($scopesList) === 0
|
count($scopesList) === 0
|
||||||
) {
|
) {
|
||||||
throw new ClientException(sprintf($this->server->getExceptionMessage('invalid_request'), 'scope'), 0);
|
throw new Exception\InvalidRequestException('scope');
|
||||||
} elseif (count($scopesList) === 0 && $this->server->getDefaultScope() !== null) {
|
} elseif (count($scopesList) === 0 && $this->server->getDefaultScope() !== null) {
|
||||||
if (is_array($this->server->getDefaultScope())) {
|
if (is_array($this->server->getDefaultScope())) {
|
||||||
$scopesList = $this->server->getDefaultScope();
|
$scopesList = $this->server->getDefaultScope();
|
||||||
@ -139,7 +139,7 @@ abstract class AbstractGrant implements GrantTypeInterface
|
|||||||
);
|
);
|
||||||
|
|
||||||
if (($scope instanceof Scope) === false) {
|
if (($scope instanceof Scope) === false) {
|
||||||
throw new ClientException(sprintf($this->server->getExceptionMessage('invalid_scope'), $scopeItem), 4);
|
throw new Exception\InvalidScopeException($scopeItem);
|
||||||
}
|
}
|
||||||
|
|
||||||
$scopes[$scope->getId()] = $scope;
|
$scopes[$scope->getId()] = $scope;
|
||||||
|
@ -24,7 +24,6 @@ use League\OAuth2\Server\Util\SecureKey;
|
|||||||
use League\OAuth2\Server\Storage\SessionInterface;
|
use League\OAuth2\Server\Storage\SessionInterface;
|
||||||
use League\OAuth2\Server\Storage\ClientInterface;
|
use League\OAuth2\Server\Storage\ClientInterface;
|
||||||
use League\OAuth2\Server\Storage\ScopeInterface;
|
use League\OAuth2\Server\Storage\ScopeInterface;
|
||||||
use League\OAuth2\Server\Exception\ClientException;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Auth code grant class
|
* Auth code grant class
|
||||||
@ -82,42 +81,27 @@ class AuthCode extends AbstractGrant
|
|||||||
// Get required params
|
// Get required params
|
||||||
$clientId = $this->server->getRequest()->request->get('client_id', null);
|
$clientId = $this->server->getRequest()->request->get('client_id', null);
|
||||||
if (is_null($clientId)) {
|
if (is_null($clientId)) {
|
||||||
throw new ClientException(
|
throw new Exception\InvalidRequestException('client_id');
|
||||||
sprintf(AuthorizationServer::getExceptionMessage('invalid_request'), 'client_id'),
|
|
||||||
0
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$redirectUri = $this->server->getRequest()->request->get('redirect_uri', null);
|
$redirectUri = $this->server->getRequest()->request->get('redirect_uri', null);
|
||||||
if (is_null($redirectUri)) {
|
if (is_null($redirectUri)) {
|
||||||
throw new ClientException(
|
throw new Exception\InvalidRequestException('redirect_uri');
|
||||||
sprintf(AuthorizationServer::getExceptionMessage('invalid_request'), 'redirect_uri'),
|
|
||||||
0
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$state = $this->server->getRequest()->request->get('state', null);
|
$state = $this->server->getRequest()->request->get('state', null);
|
||||||
if ($this->server->stateParamRequired() === true && is_null($state)) {
|
if ($this->server->stateParamRequired() === true && is_null($state)) {
|
||||||
throw new ClientException(
|
throw new Exception\InvalidRequestException('state');
|
||||||
sprintf(AuthorizationServer::getExceptionMessage('invalid_request'), 'state'),
|
|
||||||
0
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$responseType = $this->server->getRequest()->request->get('response_type', null);
|
$responseType = $this->server->getRequest()->request->get('response_type', null);
|
||||||
if (is_null($responseType)) {
|
if (is_null($responseType)) {
|
||||||
throw new ClientException(
|
throw new Exception\InvalidRequestException('response_type');
|
||||||
sprintf(AuthorizationServer::getExceptionMessage('invalid_request'), 'response_type'),
|
|
||||||
0
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ensure response type is one that is recognised
|
// Ensure response type is one that is recognised
|
||||||
if ( ! in_array($responseType, $this->server->getResponseTypes())) {
|
if ( ! in_array($responseType, $this->server->getResponseTypes())) {
|
||||||
throw new ClientException(
|
throw new Exception\UnsupportedResponseTypeException();
|
||||||
$this->server->getExceptionMessage('unsupported_response_type'),
|
|
||||||
3
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate client ID and redirect URI
|
// Validate client ID and redirect URI
|
||||||
@ -129,7 +113,7 @@ class AuthCode extends AbstractGrant
|
|||||||
);
|
);
|
||||||
|
|
||||||
if (($client instanceof Client) === false) {
|
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
|
// Validate any scopes that are in the request
|
||||||
@ -186,26 +170,17 @@ class AuthCode extends AbstractGrant
|
|||||||
// Get the required params
|
// Get the required params
|
||||||
$clientId = $this->server->getRequest()->request->get('client_id', null);
|
$clientId = $this->server->getRequest()->request->get('client_id', null);
|
||||||
if (is_null($clientId)) {
|
if (is_null($clientId)) {
|
||||||
throw new ClientException(
|
throw new Exception\InvalidRequestException('client_id');
|
||||||
sprintf(AuthorizationServer::getExceptionMessage('invalid_request'), 'client_id'),
|
|
||||||
0
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$clientSecret = $this->server->getRequest()->request->get('client_secret', null);
|
$clientSecret = $this->server->getRequest()->request->get('client_secret', null);
|
||||||
if (is_null($clientSecret)) {
|
if (is_null($clientSecret)) {
|
||||||
throw new ClientException(
|
throw new Exception\InvalidRequestException('client_secret');
|
||||||
sprintf(AuthorizationServer::getExceptionMessage('invalid_request'), 'client_secret'),
|
|
||||||
0
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$redirectUri = $this->server->getRequest()->request->get('redirect_uri', null);
|
$redirectUri = $this->server->getRequest()->request->get('redirect_uri', null);
|
||||||
if (is_null($redirectUri)) {
|
if (is_null($redirectUri)) {
|
||||||
throw new ClientException(
|
throw new Exception\InvalidRequestException('redirect_uri');
|
||||||
sprintf(AuthorizationServer::getExceptionMessage('invalid_request'), 'redirect_uri'),
|
|
||||||
0
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate client ID and client secret
|
// Validate client ID and client secret
|
||||||
@ -217,32 +192,23 @@ class AuthCode extends AbstractGrant
|
|||||||
);
|
);
|
||||||
|
|
||||||
if (($client instanceof Client) === false) {
|
if (($client instanceof Client) === false) {
|
||||||
throw new ClientException(AuthorizationServer::getExceptionMessage('invalid_client'), 8);
|
throw new Exception\InvalidClientException();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate the auth code
|
// Validate the auth code
|
||||||
$authCode = $this->server->getRequest()->request->get('code', null);
|
$authCode = $this->server->getRequest()->request->get('code', null);
|
||||||
if (is_null($authCode)) {
|
if (is_null($authCode)) {
|
||||||
throw new ClientException(
|
throw new Exception\InvalidRequestException('code');
|
||||||
sprintf(AuthorizationServer::getExceptionMessage('invalid_request'), 'code'),
|
|
||||||
0
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$code = $this->server->getStorage('auth_code')->get($authCode);
|
$code = $this->server->getStorage('auth_code')->get($authCode);
|
||||||
if (($code instanceof AC) === false) {
|
if (($code instanceof AC) === false) {
|
||||||
throw new ClientException(
|
throw new Exception\InvalidRequestException('code');
|
||||||
sprintf(AuthorizationServer::getExceptionMessage('invalid_request'), 'code'),
|
|
||||||
9
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check redirect URI presented matches redirect URI originally used in authorise request
|
// Check redirect URI presented matches redirect URI originally used in authorise request
|
||||||
if ($code->getRedirectUri() !== $redirectUri) {
|
if ($code->getRedirectUri() !== $redirectUri) {
|
||||||
throw new ClientException(
|
throw new Exception\InvalidRequestException('redirect_uri');
|
||||||
sprintf(AuthorizationServer::getExceptionMessage('invalid_request'), 'redirect_uri'),
|
|
||||||
9
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$session = $code->getSession();
|
$session = $code->getSession();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user