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>
|
|
|
|
* @copyright Copyright (c) PHP League of Extraordinary Packages
|
|
|
|
* @license http://mit-license.org/
|
|
|
|
* @link http://github.com/php-loep/oauth2-server
|
|
|
|
*/
|
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
|
|
|
|
*/
|
2013-12-24 22:31:11 +05:30
|
|
|
class RefreshToken extends AbstractToken
|
|
|
|
{
|
|
|
|
/**
|
2014-01-08 21:45:29 +05:30
|
|
|
* Access token associated to refresh token
|
2014-01-16 22:19:46 +05:30
|
|
|
* @var \League\OAuth2\Server\Entity\AccessToken
|
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-01-16 22:19:46 +05:30
|
|
|
* @param \League\OAuth2\Server\Entity\AccessToken $accessToken
|
2013-12-24 22:31:11 +05:30
|
|
|
* @return self
|
|
|
|
*/
|
|
|
|
public function setAccessToken(AccessToken $accessToken)
|
|
|
|
{
|
|
|
|
$this->accessToken = $accessToken;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return access token
|
|
|
|
* @return AccessToken
|
|
|
|
*/
|
|
|
|
public function getAccessToken()
|
|
|
|
{
|
2014-01-10 18:00:13 +05:30
|
|
|
if (! $this->accessToken instanceof AccessToken) {
|
|
|
|
$this->accessToken = $this->server->getStorage('access_token')->getByRefreshToken($this->getToken());
|
|
|
|
}
|
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
|
|
|
);
|
|
|
|
|
|
|
|
// Associate the scope with the token
|
|
|
|
foreach ($this->getScopes() as $scope) {
|
2014-01-08 21:45:29 +05:30
|
|
|
$this->server->getStorage('refresh_token')->associateScope($this->getToken(), $scope->getId());
|
2013-12-31 21:05:51 +05:30
|
|
|
}
|
2013-12-24 22:31:11 +05:30
|
|
|
}
|
2014-01-10 18:00:13 +05:30
|
|
|
|
|
|
|
/**
|
|
|
|
* {@inheritdoc}
|
|
|
|
*/
|
|
|
|
public function expire()
|
|
|
|
{
|
|
|
|
$this->server->getStorage('refresh_token')->delete($this->getToken());
|
|
|
|
}
|
2013-12-24 22:31:11 +05:30
|
|
|
}
|