mirror of
https://github.com/elyby/oauth2-server.git
synced 2024-11-15 09:47:46 +05:30
Updated response types
This commit is contained in:
parent
3721ecb40a
commit
36a1a430b5
@ -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'
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -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'))) {
|
||||
|
@ -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();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user