diff --git a/src/TokenTypes/AbstractTokenType.php b/src/ResponseTypes/AbstractResponseType.php similarity index 61% rename from src/TokenTypes/AbstractTokenType.php rename to src/ResponseTypes/AbstractResponseType.php index 47900ca8..ed85c1c4 100644 --- a/src/TokenTypes/AbstractTokenType.php +++ b/src/ResponseTypes/AbstractResponseType.php @@ -1,6 +1,6 @@ @@ -9,15 +9,14 @@ * @link https://github.com/thephpleague/oauth2-server */ -namespace League\OAuth2\Server\TokenTypes; +namespace League\OAuth2\Server\ResponseTypes; use League\OAuth2\Server\Entities\Interfaces\AccessTokenEntityInterface; -use Symfony\Component\HttpFoundation\Response; -abstract class AbstractTokenType implements TokenTypeInterface +abstract class AbstractResponseType implements ResponseTypeInterface { /** - * Response array + * Response array for JSON serialization * * @var array */ @@ -51,20 +50,4 @@ abstract class AbstractTokenType implements TokenTypeInterface { $this->accessToken = $accessToken; } - - /** - * @return \Symfony\Component\HttpFoundation\Response - */ - public function generateHttpResponse() - { - return new Response( - json_encode($this->generateResponse()), - 200, - [ - 'Content-type' => 'application/json', - 'Cache-Control' => 'no-store', - 'Pragma' => 'no-cache' - ] - ); - } } diff --git a/src/TokenTypes/BearerTokenType.php b/src/ResponseTypes/BearerTokenResponse.php similarity index 91% rename from src/TokenTypes/BearerTokenType.php rename to src/ResponseTypes/BearerTokenResponse.php index bc22caab..3ee5671f 100644 --- a/src/TokenTypes/BearerTokenType.php +++ b/src/ResponseTypes/BearerTokenResponse.php @@ -9,17 +9,17 @@ * @link https://github.com/thephpleague/oauth2-server */ -namespace League\OAuth2\Server\TokenTypes; +namespace League\OAuth2\Server\ResponseTypes; use Psr\Http\Message\ServerRequestInterface; use Zend\Diactoros\Response; -class BearerTokenType extends AbstractTokenType +class BearerTokenResponse extends AbstractResponseType { /** * {@inheritdoc} */ - public function generateResponse() + public function generateHttpResponse() { $values = [ 'access_token' => $this->accessToken->getIdentifier(), diff --git a/src/TokenTypes/JsonWebTokenType.php b/src/ResponseTypes/JsonWebTokenType.php similarity index 100% rename from src/TokenTypes/JsonWebTokenType.php rename to src/ResponseTypes/JsonWebTokenType.php diff --git a/src/TokenTypes/MAC.php b/src/ResponseTypes/MAC.php similarity index 100% rename from src/TokenTypes/MAC.php rename to src/ResponseTypes/MAC.php diff --git a/src/ResponseTypes/ResponseTypeInterface.php b/src/ResponseTypes/ResponseTypeInterface.php new file mode 100644 index 00000000..039cf342 --- /dev/null +++ b/src/ResponseTypes/ResponseTypeInterface.php @@ -0,0 +1,55 @@ + + * @copyright Copyright (c) Alex Bilbie + * @license http://mit-license.org/ + * @link https://github.com/thephpleague/oauth2-server + */ + +namespace League\OAuth2\Server\ResponseTypes; + +use League\OAuth2\Server\Entities\Interfaces\AccessTokenEntityInterface; +use Psr\Http\Message\ResponseInterface; +use Psr\Http\Message\ServerRequestInterface; + +interface ResponseTypeInterface +{ + /** + * @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(); +}