diff --git a/src/Exception/InvalidClientException.php b/src/Exception/InvalidClientException.php deleted file mode 100644 index ba01d277..00000000 --- a/src/Exception/InvalidClientException.php +++ /dev/null @@ -1,36 +0,0 @@ - - * @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.'); - } -} diff --git a/src/Exception/InvalidGrantException.php b/src/Exception/InvalidGrantException.php deleted file mode 100644 index 051330e9..00000000 --- a/src/Exception/InvalidGrantException.php +++ /dev/null @@ -1,42 +0,0 @@ - - * @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 - ) - ); - } -} diff --git a/src/Exception/InvalidRequestException.php b/src/Exception/InvalidRequestException.php deleted file mode 100644 index d4d0c3a1..00000000 --- a/src/Exception/InvalidRequestException.php +++ /dev/null @@ -1,44 +0,0 @@ - - * @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; - } -} diff --git a/src/Exception/InvalidScopeException.php b/src/Exception/InvalidScopeException.php deleted file mode 100644 index f0574f8d..00000000 --- a/src/Exception/InvalidScopeException.php +++ /dev/null @@ -1,44 +0,0 @@ - - * @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; - } -} diff --git a/src/Exception/OAuthException.php b/src/Exception/OAuthException.php deleted file mode 100644 index 3fb7840b..00000000 --- a/src/Exception/OAuthException.php +++ /dev/null @@ -1,164 +0,0 @@ - - * @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() - ); - } -} diff --git a/src/Exception/UnsupportedGrantTypeException.php b/src/Exception/UnsupportedGrantTypeException.php deleted file mode 100644 index 5a4f1d90..00000000 --- a/src/Exception/UnsupportedGrantTypeException.php +++ /dev/null @@ -1,42 +0,0 @@ - - * @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 - ) - ); - } -} diff --git a/src/TokenTypes/TokenTypeInterface.php b/src/TokenTypes/TokenTypeInterface.php deleted file mode 100644 index 3946eeb9..00000000 --- a/src/TokenTypes/TokenTypeInterface.php +++ /dev/null @@ -1,62 +0,0 @@ - - * @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(); -}