mirror of
https://github.com/elyby/oauth2-server.git
synced 2025-05-31 14:12:07 +05:30
Removed unused exception parameters
This commit is contained in:
@@ -33,14 +33,15 @@ class OAuthServerException extends \Exception
|
||||
* Throw a new exception.
|
||||
*
|
||||
* @param string $message Error message
|
||||
* @param int $code Error code
|
||||
* @param string $errorType Error type
|
||||
* @param int $httpStatusCode HTTP status code to send (default = 400)
|
||||
* @param null|string $hint A helper hint
|
||||
* @param null|string $redirectUri A HTTP URI to redirect the user back to
|
||||
*/
|
||||
public function __construct($message, $errorType, $httpStatusCode = 400, $hint = null, $redirectUri = null)
|
||||
public function __construct($message, $code, $errorType, $httpStatusCode = 400, $hint = null, $redirectUri = null)
|
||||
{
|
||||
parent::__construct($message);
|
||||
parent::__construct($message, $code);
|
||||
$this->httpStatusCode = $httpStatusCode;
|
||||
$this->errorType = $errorType;
|
||||
$this->hint = $hint;
|
||||
@@ -49,110 +50,73 @@ class OAuthServerException extends \Exception
|
||||
|
||||
/**
|
||||
* Invalid grant type error.
|
||||
*
|
||||
* @param null|string $localizedError
|
||||
* @param null|string $localizedHint
|
||||
*
|
||||
* @return static
|
||||
*/
|
||||
public static function invalidGrantType(
|
||||
$localizedError = null,
|
||||
$localizedHint = null
|
||||
) {
|
||||
$errorMessage = (is_null($localizedError))
|
||||
? 'The provided authorization grant is invalid, expired, revoked, does not match '.
|
||||
'the redirection URI used in the authorization request, or was issued to another client.'
|
||||
: $localizedError;
|
||||
$hint = (is_null($localizedHint))
|
||||
? 'Check the `grant_type` parameter'
|
||||
: $localizedHint;
|
||||
public static function invalidGrantType()
|
||||
{
|
||||
$errorMessage = 'The provided authorization grant is invalid, expired, revoked, does not match ' .
|
||||
'the redirection URI used in the authorization request, or was issued to another client.';
|
||||
$hint = 'Check the `grant_type` parameter';
|
||||
|
||||
return new static($errorMessage, 'invalid_grant', 400, $hint);
|
||||
return new static($errorMessage, 1, 'invalid_grant', 400, $hint);
|
||||
}
|
||||
|
||||
/**
|
||||
* Unsupported grant type error.
|
||||
*
|
||||
* @param null|string $localizedError
|
||||
* @param null|string $localizedHint
|
||||
*
|
||||
* @return static
|
||||
*/
|
||||
public static function unsupportedGrantType(
|
||||
$localizedError = null,
|
||||
$localizedHint = null
|
||||
) {
|
||||
$errorMessage = (is_null($localizedError))
|
||||
? 'The authorization grant type is not supported by the authorization server.'
|
||||
: $localizedError;
|
||||
$hint = (is_null($localizedHint))
|
||||
? 'Check the `grant_type` parameter'
|
||||
: $localizedHint;
|
||||
public static function unsupportedGrantType()
|
||||
{
|
||||
$errorMessage = 'The authorization grant type is not supported by the authorization server.';
|
||||
$hint = 'Check the `grant_type` parameter';
|
||||
|
||||
return new static($errorMessage, 'unsupported_grant_type', 400, $hint);
|
||||
return new static($errorMessage, 2, 'unsupported_grant_type', 400, $hint);
|
||||
}
|
||||
|
||||
/**
|
||||
* Invalid request error.
|
||||
*
|
||||
* @param string $parameter The invalid parameter
|
||||
* @param null|string $localizedError
|
||||
* @param null|string $localizedHint
|
||||
* @param string $parameter The invalid parameter
|
||||
* @param string|null $hint
|
||||
*
|
||||
* @return static
|
||||
*/
|
||||
public static function invalidRequest(
|
||||
$parameter,
|
||||
$localizedError = null,
|
||||
$localizedHint = null
|
||||
) {
|
||||
$errorMessage = (is_null($localizedError))
|
||||
? 'The request is missing a required parameter, includes an invalid parameter value, '.
|
||||
'includes a parameter more than once, or is otherwise malformed.'
|
||||
: $localizedError;
|
||||
$hint = (is_null($localizedHint))
|
||||
? sprintf('Check the `%s` parameter', $parameter)
|
||||
: sprintf($localizedHint, $parameter);
|
||||
public static function invalidRequest($parameter, $hint = null)
|
||||
{
|
||||
$errorMessage = 'The request is missing a required parameter, includes an invalid parameter value, ' .
|
||||
'includes a parameter more than once, or is otherwise malformed.';
|
||||
$hint = ($hint === null) ? sprintf('Check the `%s` parameter', $parameter) : $hint;
|
||||
|
||||
return new static($errorMessage, 'invalid_request', 400, $hint);
|
||||
return new static($errorMessage, 3, 'invalid_request', 400, $hint);
|
||||
}
|
||||
|
||||
/**
|
||||
* Invalid client error.
|
||||
*
|
||||
* @param null|string $localizedError
|
||||
*
|
||||
* @return static
|
||||
*/
|
||||
public static function invalidClient($localizedError = null)
|
||||
public static function invalidClient()
|
||||
{
|
||||
$errorMessage = (is_null($localizedError))
|
||||
? 'Client authentication failed'
|
||||
: $localizedError;
|
||||
$errorMessage = 'Client authentication failed';
|
||||
|
||||
return new static($errorMessage, 'invalid_client', 401);
|
||||
return new static($errorMessage, 4, 'invalid_client', 401);
|
||||
}
|
||||
|
||||
/**
|
||||
* Invalid scope error.
|
||||
*
|
||||
* @param string $scope The bad scope
|
||||
* @param null|string $localizedError A localized error message
|
||||
* @param null|string $localizedHint A localized error hint
|
||||
* @param null|string $redirectUri A HTTP URI to redirect the user back to
|
||||
* @param string $scope The bad scope
|
||||
* @param null|string $redirectUri A HTTP URI to redirect the user back to
|
||||
*
|
||||
* @return static
|
||||
*/
|
||||
public static function invalidScope($scope, $localizedError = null, $localizedHint = null, $redirectUri = null)
|
||||
public static function invalidScope($scope, $redirectUri = null)
|
||||
{
|
||||
$errorMessage = (is_null($localizedError))
|
||||
? 'The requested scope is invalid, unknown, or malformed'
|
||||
: $localizedError;
|
||||
$hint = (is_null($localizedHint))
|
||||
? sprintf('Check the `%s` scope', $scope)
|
||||
: sprintf($localizedHint, $scope);
|
||||
$errorMessage = 'The requested scope is invalid, unknown, or malformed';
|
||||
$hint = sprintf('Check the `%s` scope', $scope);
|
||||
|
||||
return new static($errorMessage, 'invalid_scope', 400, $hint, $redirectUri);
|
||||
return new static($errorMessage, 5, 'invalid_scope', 400, $hint, $redirectUri);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -162,7 +126,7 @@ class OAuthServerException extends \Exception
|
||||
*/
|
||||
public static function invalidCredentials()
|
||||
{
|
||||
return new static('The user credentials were incorrect.', 'invalid_credentials', 401);
|
||||
return new static('The user credentials were incorrect.', 6, 'invalid_credentials', 401);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -176,7 +140,8 @@ class OAuthServerException extends \Exception
|
||||
{
|
||||
return new static(
|
||||
'The authorization server encountered an unexpected condition which prevented it from fulfilling'
|
||||
.'the request.',
|
||||
. 'the request.',
|
||||
7,
|
||||
'server_error',
|
||||
500,
|
||||
$hint
|
||||
@@ -192,7 +157,7 @@ class OAuthServerException extends \Exception
|
||||
*/
|
||||
public static function invalidRefreshToken($hint = null)
|
||||
{
|
||||
return new static('The refresh token is invalid.', 'invalid_request', 400, $hint);
|
||||
return new static('The refresh token is invalid.', 8, 'invalid_request', 400, $hint);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -208,6 +173,7 @@ class OAuthServerException extends \Exception
|
||||
return new static(
|
||||
'The resource owner or authorization server denied the request.',
|
||||
'access_denied',
|
||||
9,
|
||||
401,
|
||||
$hint,
|
||||
$redirectUri
|
||||
@@ -304,7 +270,7 @@ class OAuthServerException extends \Exception
|
||||
}
|
||||
}
|
||||
if ($authScheme !== null) {
|
||||
$headers[] = 'WWW-Authenticate: '.$authScheme.' realm="OAuth"';
|
||||
$headers[] = 'WWW-Authenticate: ' . $authScheme . ' realm="OAuth"';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user