2013-12-24 22:31:11 +05:30
|
|
|
<?php
|
2014-01-08 21:45:29 +05:30
|
|
|
/**
|
|
|
|
* OAuth 2.0 Refresh token entity
|
|
|
|
*
|
|
|
|
* @package league/oauth2-server
|
|
|
|
* @author Alex Bilbie <hello@alexbilbie.com>
|
2014-03-10 01:04:23 +05:30
|
|
|
* @copyright Copyright (c) Alex Bilbie
|
2014-01-08 21:45:29 +05:30
|
|
|
* @license http://mit-license.org/
|
2014-03-10 01:35:38 +05:30
|
|
|
* @link https://github.com/thephpleague/oauth2-server
|
2014-01-08 21:45:29 +05:30
|
|
|
*/
|
2013-12-24 22:31:11 +05:30
|
|
|
|
2014-01-16 22:19:46 +05:30
|
|
|
namespace League\OAuth2\Server\Entity;
|
2013-12-24 22:31:11 +05:30
|
|
|
|
|
|
|
use League\OAuth2\Server\Storage\SessionStorageInterface;
|
|
|
|
use League\OAuth2\Server\Storage\RefreshTokenInterface;
|
|
|
|
use League\OAuth2\Server\Util\SecureKey;
|
|
|
|
use League\OAuth2\Server\Exception\InvalidAccessTokenException;
|
2014-01-08 21:45:29 +05:30
|
|
|
use Symfony\Component\HttpFoundation\ParameterBag;
|
2013-12-24 22:31:11 +05:30
|
|
|
|
2014-01-08 21:45:29 +05:30
|
|
|
/**
|
|
|
|
* Refresh token entity class
|
|
|
|
*/
|
2014-05-02 19:42:00 +05:30
|
|
|
class RefreshTokenEntity extends AbstractTokenEntity
|
2013-12-24 22:31:11 +05:30
|
|
|
{
|
|
|
|
/**
|
2014-01-08 21:45:29 +05:30
|
|
|
* Access token associated to refresh token
|
2014-05-02 21:51:53 +05:30
|
|
|
* @var \League\OAuth2\Server\Entity\AccessTokenEntity
|
2013-12-24 22:31:11 +05:30
|
|
|
*/
|
2014-01-08 21:45:29 +05:30
|
|
|
protected $accessToken;
|
2013-12-24 22:31:11 +05:30
|
|
|
|
|
|
|
/**
|
|
|
|
* Associate an access token
|
2014-05-02 19:42:00 +05:30
|
|
|
* @param \League\OAuth2\Server\Entity\AccessTokenEntity $accessToken
|
2013-12-24 22:31:11 +05:30
|
|
|
* @return self
|
|
|
|
*/
|
2014-05-02 19:42:00 +05:30
|
|
|
public function setAccessToken(AccessTokenEntity $accessToken)
|
2013-12-24 22:31:11 +05:30
|
|
|
{
|
|
|
|
$this->accessToken = $accessToken;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return access token
|
|
|
|
* @return AccessToken
|
|
|
|
*/
|
|
|
|
public function getAccessToken()
|
|
|
|
{
|
2014-05-02 19:42:00 +05:30
|
|
|
if (! $this->accessToken instanceof AccessTokenEntity) {
|
2014-05-01 19:17:01 +05:30
|
|
|
$this->accessToken = $this->server->getStorage('access_token')->getByRefreshToken($this);
|
2014-01-10 18:00:13 +05:30
|
|
|
}
|
2013-12-24 22:31:11 +05:30
|
|
|
return $this->accessToken;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-01-08 21:45:29 +05:30
|
|
|
* {@inheritdoc}
|
2013-12-24 22:31:11 +05:30
|
|
|
*/
|
|
|
|
public function save()
|
|
|
|
{
|
2014-01-10 18:00:13 +05:30
|
|
|
$this->server->getStorage('refresh_token')->create(
|
2013-12-31 21:05:51 +05:30
|
|
|
$this->getToken(),
|
2013-12-24 22:31:11 +05:30
|
|
|
$this->getExpireTime(),
|
2013-12-31 21:05:51 +05:30
|
|
|
$this->getAccessToken()->getToken()
|
2013-12-24 22:31:11 +05:30
|
|
|
);
|
|
|
|
}
|
2014-01-10 18:00:13 +05:30
|
|
|
|
|
|
|
/**
|
|
|
|
* {@inheritdoc}
|
|
|
|
*/
|
|
|
|
public function expire()
|
|
|
|
{
|
2014-05-02 21:51:53 +05:30
|
|
|
$this->server->getStorage('refresh_token')->delete($this);
|
2014-01-10 18:00:13 +05:30
|
|
|
}
|
2013-12-24 22:31:11 +05:30
|
|
|
}
|