TokenType -> ResponseType

This commit is contained in:
Alex Bilbie 2015-11-13 17:38:23 +00:00
parent 0a602cb022
commit 1442842da9
5 changed files with 62 additions and 24 deletions

View File

@ -1,6 +1,6 @@
<?php <?php
/** /**
* OAuth 2.0 Abstract Token Type * OAuth 2.0 Abstract Response Type
* *
* @package league/oauth2-server * @package league/oauth2-server
* @author Alex Bilbie <hello@alexbilbie.com> * @author Alex Bilbie <hello@alexbilbie.com>
@ -9,15 +9,14 @@
* @link https://github.com/thephpleague/oauth2-server * @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 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 * @var array
*/ */
@ -51,20 +50,4 @@ abstract class AbstractTokenType implements TokenTypeInterface
{ {
$this->accessToken = $accessToken; $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'
]
);
}
} }

View File

@ -9,17 +9,17 @@
* @link https://github.com/thephpleague/oauth2-server * @link https://github.com/thephpleague/oauth2-server
*/ */
namespace League\OAuth2\Server\TokenTypes; namespace League\OAuth2\Server\ResponseTypes;
use Psr\Http\Message\ServerRequestInterface; use Psr\Http\Message\ServerRequestInterface;
use Zend\Diactoros\Response; use Zend\Diactoros\Response;
class BearerTokenType extends AbstractTokenType class BearerTokenResponse extends AbstractResponseType
{ {
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function generateResponse() public function generateHttpResponse()
{ {
$values = [ $values = [
'access_token' => $this->accessToken->getIdentifier(), 'access_token' => $this->accessToken->getIdentifier(),

View File

@ -0,0 +1,55 @@
<?php
/**
* OAuth 2.0 Response 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\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();
}