mirror of
https://github.com/elyby/oauth2-server.git
synced 2024-11-15 17:56:14 +05:30
Removed old exceptions
This commit is contained in:
parent
82413513e8
commit
41c7a6e731
@ -1,36 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* OAuth 2.0 Invalid Client Exception
|
||||
*
|
||||
* @package league/oauth2-server
|
||||
* @author Alex Bilbie <hello@alexbilbie.com>
|
||||
* @copyright Copyright (c) Alex Bilbie
|
||||
* @license http://mit-license.org/
|
||||
* @link https://github.com/thephpleague/oauth2-server
|
||||
*/
|
||||
|
||||
namespace League\OAuth2\Server\Exception;
|
||||
|
||||
/**
|
||||
* Exception class
|
||||
*/
|
||||
class InvalidClientException extends OAuthException
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public $httpStatusCode = 401;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public $errorType = 'invalid_client';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct('Client authentication failed.');
|
||||
}
|
||||
}
|
@ -1,42 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* OAuth 2.0 Invalid Grant Exception
|
||||
*
|
||||
* @package league/oauth2-server
|
||||
* @author Alex Bilbie <hello@alexbilbie.com>
|
||||
* @copyright Copyright (c) Alex Bilbie
|
||||
* @license http://mit-license.org/
|
||||
* @link https://github.com/thephpleague/oauth2-server
|
||||
*/
|
||||
|
||||
namespace League\OAuth2\Server\Exception;
|
||||
|
||||
/**
|
||||
* Exception class
|
||||
*/
|
||||
class InvalidGrantException extends OAuthException
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public $httpStatusCode = 400;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public $errorType = 'invalid_grant';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
|
||||
public function __construct($parameter)
|
||||
{
|
||||
parent::__construct(
|
||||
sprintf(
|
||||
'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. Check the "%s" parameter.',
|
||||
$parameter
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
@ -1,44 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* OAuth 2.0 Invalid Request Exception
|
||||
*
|
||||
* @package league/oauth2-server
|
||||
* @author Alex Bilbie <hello@alexbilbie.com>
|
||||
* @copyright Copyright (c) Alex Bilbie
|
||||
* @license http://mit-license.org/
|
||||
* @link https://github.com/thephpleague/oauth2-server
|
||||
*/
|
||||
|
||||
namespace League\OAuth2\Server\Exception;
|
||||
|
||||
/**
|
||||
* Exception class
|
||||
*/
|
||||
class InvalidRequestException extends OAuthException
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public $httpStatusCode = 400;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public $errorType = 'invalid_request';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
|
||||
public function __construct($parameter, $redirectUri = null, $description = null)
|
||||
{
|
||||
parent::__construct(
|
||||
sprintf(
|
||||
'The request is missing a required parameter, includes an invalid parameter value, includes a parameter more than once, or is otherwise malformed. Check the "%s" parameter.',
|
||||
$parameter
|
||||
)
|
||||
);
|
||||
|
||||
$this->redirectUri = $redirectUri;
|
||||
}
|
||||
}
|
@ -1,44 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* OAuth 2.0 Invalid Scope Exception
|
||||
*
|
||||
* @package league/oauth2-server
|
||||
* @author Alex Bilbie <hello@alexbilbie.com>
|
||||
* @copyright Copyright (c) Alex Bilbie
|
||||
* @license http://mit-license.org/
|
||||
* @link https://github.com/thephpleague/oauth2-server
|
||||
*/
|
||||
|
||||
namespace League\OAuth2\Server\Exception;
|
||||
|
||||
/**
|
||||
* Exception class
|
||||
*/
|
||||
class InvalidScopeException extends OAuthException
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public $httpStatusCode = 400;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public $errorType = 'invalid_scope';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
|
||||
public function __construct($parameter, $redirectUri = null)
|
||||
{
|
||||
parent::__construct(
|
||||
sprintf(
|
||||
'The requested scope is invalid, unknown, or malformed. Check the "%s" scope.',
|
||||
$parameter
|
||||
)
|
||||
);
|
||||
|
||||
$this->redirectUri = $redirectUri;
|
||||
}
|
||||
}
|
@ -1,164 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* OAuth 2.0 Base Exception
|
||||
*
|
||||
* @package league/oauth2-server
|
||||
* @author Alex Bilbie <hello@alexbilbie.com>
|
||||
* @copyright Copyright (c) Alex Bilbie
|
||||
* @license http://mit-license.org/
|
||||
* @link https://github.com/thephpleague/oauth2-server
|
||||
*/
|
||||
|
||||
namespace League\OAuth2\Server\Exception;
|
||||
|
||||
use League\OAuth2\Server\Utils\RedirectUri;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Zend\Diactoros\Request;
|
||||
use Zend\Diactoros\Response;
|
||||
use Zend\Diactoros\ServerRequest;
|
||||
|
||||
/**
|
||||
* Exception class
|
||||
*/
|
||||
class OAuthException extends \Exception
|
||||
{
|
||||
/**
|
||||
* The HTTP status code for this exception that should be sent in the response
|
||||
*/
|
||||
public $httpStatusCode = 400;
|
||||
|
||||
/**
|
||||
* Redirect URI if the server should redirect back to the client
|
||||
*
|
||||
* @var string|null
|
||||
*/
|
||||
public $redirectUri = null;
|
||||
|
||||
/**
|
||||
* The exception type
|
||||
*/
|
||||
public $errorType = '';
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $description;
|
||||
|
||||
/**
|
||||
* Throw a new exception
|
||||
*
|
||||
* @param string $msg Exception Message
|
||||
* @param string|null $description Description of error
|
||||
*/
|
||||
public function __construct($msg = 'An error occurred', $description = null)
|
||||
{
|
||||
parent::__construct($msg);
|
||||
$this->description = $description;
|
||||
}
|
||||
|
||||
/**
|
||||
* Should the server redirect back to the client?
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function shouldRedirect()
|
||||
{
|
||||
return is_null($this->redirectUri) ? false : true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return redirect URI if set
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function getRedirectUri()
|
||||
{
|
||||
return RedirectUri::make(
|
||||
$this->redirectUri,
|
||||
[
|
||||
'error' => $this->errorType,
|
||||
'message' => $this->getMessage(),
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all headers that have to be send with the error response
|
||||
*
|
||||
* @return array Array with header values
|
||||
*/
|
||||
public function getHttpHeaders()
|
||||
{
|
||||
$headers = [
|
||||
'Content-type' => 'application/json'
|
||||
];
|
||||
switch ($this->httpStatusCode) {
|
||||
case 401:
|
||||
$headers[] = 'HTTP/1.1 401 Unauthorized';
|
||||
break;
|
||||
case 500:
|
||||
$headers[] = 'HTTP/1.1 500 Internal Server Error';
|
||||
break;
|
||||
case 501:
|
||||
$headers[] = 'HTTP/1.1 501 Not Implemented';
|
||||
break;
|
||||
case 400:
|
||||
default:
|
||||
$headers[] = 'HTTP/1.1 400 Bad Request';
|
||||
break;
|
||||
}
|
||||
|
||||
// Add "WWW-Authenticate" header
|
||||
//
|
||||
// RFC 6749, section 5.2.:
|
||||
// "If the client attempted to authenticate via the 'Authorization'
|
||||
// request header field, the authorization server MUST
|
||||
// respond with an HTTP 401 (Unauthorized) status code and
|
||||
// include the "WWW-Authenticate" response header field
|
||||
// matching the authentication scheme used by the client.
|
||||
// @codeCoverageIgnoreStart
|
||||
if ($this->errorType === 'invalid_client') {
|
||||
$authScheme = null;
|
||||
$request = new ServerRequest();
|
||||
if ($request->getServerParams()['PHP_AUTH_USER'] !== null) {
|
||||
$authScheme = 'Basic';
|
||||
} else {
|
||||
$authHeader = $request->getHeader('authorization');
|
||||
if ($authHeader !== null) {
|
||||
if (strpos($authHeader, 'Bearer') === 0) {
|
||||
$authScheme = 'Bearer';
|
||||
} elseif (strpos($authHeader, 'Basic') === 0) {
|
||||
$authScheme = 'Basic';
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($authScheme !== null) {
|
||||
$headers[] = 'WWW-Authenticate: ' . $authScheme . ' realm="OAuth"';
|
||||
}
|
||||
}
|
||||
// @codeCoverageIgnoreEnd
|
||||
return $headers;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate a HTTP response
|
||||
* @return ResponseInterface
|
||||
*/
|
||||
public function generateHttpResponse()
|
||||
{
|
||||
$payload = [
|
||||
'error' => $this->errorType,
|
||||
'message' => $this->getMessage()
|
||||
];
|
||||
|
||||
if ($this->description !== null) {
|
||||
$payload['description'] = $this->description;
|
||||
}
|
||||
|
||||
return new Response(
|
||||
json_encode($payload),
|
||||
$this->httpStatusCode,
|
||||
$this->getHttpHeaders()
|
||||
);
|
||||
}
|
||||
}
|
@ -1,42 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* OAuth 2.0 Invalid Request Exception
|
||||
*
|
||||
* @package league/oauth2-server
|
||||
* @author Alex Bilbie <hello@alexbilbie.com>
|
||||
* @copyright Copyright (c) Alex Bilbie
|
||||
* @license http://mit-license.org/
|
||||
* @link https://github.com/thephpleague/oauth2-server
|
||||
*/
|
||||
|
||||
namespace League\OAuth2\Server\Exception;
|
||||
|
||||
/**
|
||||
* Exception class
|
||||
*/
|
||||
class UnsupportedGrantTypeException extends OAuthException
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public $httpStatusCode = 400;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public $errorType = 'unsupported_grant_type';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
|
||||
public function __construct($parameter)
|
||||
{
|
||||
parent::__construct(
|
||||
sprintf(
|
||||
'The authorization grant type "%s" is not supported by the authorization server.',
|
||||
$parameter
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
@ -1,62 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* OAuth 2.0 Token Type Interface
|
||||
*
|
||||
* @package league/oauth2-server
|
||||
* @author Alex Bilbie <hello@alexbilbie.com>
|
||||
* @copyright Copyright (c) Alex Bilbie
|
||||
* @license http://mit-license.org/
|
||||
* @link https://github.com/thephpleague/oauth2-server
|
||||
*/
|
||||
|
||||
namespace League\OAuth2\Server\TokenTypes;
|
||||
|
||||
use League\OAuth2\Server\Entities\Interfaces\AccessTokenEntityInterface;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
|
||||
interface TokenTypeInterface
|
||||
{
|
||||
/**
|
||||
* Generate a response
|
||||
*
|
||||
* @return ResponseInterface
|
||||
*/
|
||||
public function generateResponse();
|
||||
|
||||
/**
|
||||
* @param \League\OAuth2\Server\Entities\Interfaces\AccessTokenEntityInterface $accessToken
|
||||
*/
|
||||
public function setAccessToken(AccessTokenEntityInterface $accessToken);
|
||||
|
||||
/**
|
||||
* Set a key/value response pair
|
||||
*
|
||||
* @param string $key
|
||||
* @param mixed $value
|
||||
*/
|
||||
public function setParam($key, $value);
|
||||
|
||||
/**
|
||||
* Get a key from the response array
|
||||
*
|
||||
* @param string $key
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getParam($key);
|
||||
|
||||
/**
|
||||
* Determine the access token in the authorization header
|
||||
*
|
||||
* @param ServerRequestInterface $request
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function determineAccessTokenInHeader(ServerRequestInterface $request);
|
||||
|
||||
/**
|
||||
* @return ResponseInterface
|
||||
*/
|
||||
public function generateHttpResponse();
|
||||
}
|
Loading…
Reference in New Issue
Block a user