Updated response types

This commit is contained in:
Alex Bilbie 2015-04-05 17:01:00 +01:00
parent 3721ecb40a
commit 36a1a430b5
3 changed files with 30 additions and 11 deletions

View File

@ -9,11 +9,12 @@
* @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
@ -50,4 +51,20 @@ 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'
]
);
}
}

View File

@ -9,12 +9,11 @@
* @link https://github.com/thephpleague/oauth2-server
*/
namespace League\OAuth2\Server\TokenTypes;
namespace League\OAuth2\Server\ResponseTypes;
use Period\Period;
use Symfony\Component\HttpFoundation\Request;
class BearerTokenType extends AbstractTokenType
class BearerTokenResponseType extends AbstractResponseType
{
/**
* {@inheritdoc}
@ -24,10 +23,7 @@ class BearerTokenType extends AbstractTokenType
$return = [
'access_token' => $this->accessToken->getIdentifier(),
'token_type' => 'Bearer',
'expires_in' => (new Period(
new \DateTime(),
$this->accessToken->getExpiryDateTime())
)->getTimestampInterval(),
'expires_in' => $this->accessToken->getExpiryDateTime()->getTimestamp() - (new \DateTime())->getTimestamp()
];
if (!is_null($this->getParam('refresh_token'))) {

View File

@ -9,14 +9,15 @@
* @link https://github.com/thephpleague/oauth2-server
*/
namespace League\OAuth2\Server\TokenTypes;
namespace League\OAuth2\Server\ResponseTypes;
use League\OAuth2\Server\AbstractServer;
use League\OAuth2\Server\Entities\Interfaces\AccessTokenEntityInterface;
use League\OAuth2\Server\Entity\SessionEntity;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
interface TokenTypeInterface
interface ResponseTypeInterface
{
/**
* Generate a response
@ -55,4 +56,9 @@ interface TokenTypeInterface
* @return string
*/
public function determineAccessTokenInHeader(Request $request);
/**
* @return Response
*/
public function generateHttpResponse();
}