mirror of
https://github.com/elyby/oauth2-server.git
synced 2024-12-23 05:29:52 +05:30
Added setAccessTokenId method
This commit is contained in:
parent
8be92d413d
commit
07a42f6f43
@ -20,16 +20,34 @@ class RefreshTokenEntity extends AbstractTokenEntity
|
|||||||
* Access token associated to refresh token
|
* Access token associated to refresh token
|
||||||
* @var \League\OAuth2\Server\Entity\AccessTokenEntity
|
* @var \League\OAuth2\Server\Entity\AccessTokenEntity
|
||||||
*/
|
*/
|
||||||
protected $accessToken;
|
protected $accessTokenEntity;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Id of the access token
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $accessTokenId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the ID of the associated access token
|
||||||
|
* @param string $accessToken
|
||||||
|
* @return self
|
||||||
|
*/
|
||||||
|
public function setAccessTokenId($accessTokenId)
|
||||||
|
{
|
||||||
|
$this->accessTokenId = $accessTokenId;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Associate an access token
|
* Associate an access token
|
||||||
* @param \League\OAuth2\Server\Entity\AccessTokenEntity $accessToken
|
* @param \League\OAuth2\Server\Entity\AccessTokenEntity $accessToken
|
||||||
* @return self
|
* @return self
|
||||||
*/
|
*/
|
||||||
public function setAccessToken(AccessTokenEntity $accessToken)
|
public function setAccessToken(AccessTokenEntity $accessTokenEntity)
|
||||||
{
|
{
|
||||||
$this->accessToken = $accessToken;
|
$this->accessTokenEntity = $accessTokenEntity;
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
@ -40,11 +58,11 @@ class RefreshTokenEntity extends AbstractTokenEntity
|
|||||||
*/
|
*/
|
||||||
public function getAccessToken()
|
public function getAccessToken()
|
||||||
{
|
{
|
||||||
if (! $this->accessToken instanceof AccessTokenEntity) {
|
if (! $this->accessTokenEntity instanceof AccessTokenEntity) {
|
||||||
$this->accessToken = $this->server->getStorage('access_token')->getByRefreshToken($this);
|
$this->accessTokenEntity = $this->server->getStorage('access_token')->get($this->accessTokenId);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->accessToken;
|
return $this->accessTokenEntity;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -8,8 +8,21 @@ use League\OAuth2\Server\Entity\AccessTokenEntity;
|
|||||||
use League\OAuth2\Server\Entity\RefreshTokenEntity;
|
use League\OAuth2\Server\Entity\RefreshTokenEntity;
|
||||||
use \Mockery as M;
|
use \Mockery as M;
|
||||||
|
|
||||||
class RefreshTokenTest extends \PHPUnit_Framework_TestCase
|
class RefreshTokenEntityTest extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
|
public function testSetAccessTokenId()
|
||||||
|
{
|
||||||
|
$server = M::mock('League\OAuth2\Server\AbstractServer');
|
||||||
|
$entity = new RefreshTokenEntity($server);
|
||||||
|
$entity->setAccessTokenId('foobar');
|
||||||
|
|
||||||
|
$reflector = new \ReflectionClass($entity);
|
||||||
|
$accessTokenProperty = $reflector->getProperty('accessTokenId');
|
||||||
|
$accessTokenProperty->setAccessible(true);
|
||||||
|
|
||||||
|
$this->assertSame($accessTokenProperty->getValue($entity), 'foobar');
|
||||||
|
}
|
||||||
|
|
||||||
public function testSetAccessToken()
|
public function testSetAccessToken()
|
||||||
{
|
{
|
||||||
$server = M::mock('League\OAuth2\Server\AbstractServer');
|
$server = M::mock('League\OAuth2\Server\AbstractServer');
|
||||||
@ -17,7 +30,7 @@ class RefreshTokenTest extends \PHPUnit_Framework_TestCase
|
|||||||
$entity->setAccessToken((new AccessTokenEntity($server)));
|
$entity->setAccessToken((new AccessTokenEntity($server)));
|
||||||
|
|
||||||
$reflector = new \ReflectionClass($entity);
|
$reflector = new \ReflectionClass($entity);
|
||||||
$accessTokenProperty = $reflector->getProperty('accessToken');
|
$accessTokenProperty = $reflector->getProperty('accessTokenEntity');
|
||||||
$accessTokenProperty->setAccessible(true);
|
$accessTokenProperty->setAccessible(true);
|
||||||
|
|
||||||
$this->assertTrue($accessTokenProperty->getValue($entity) instanceof AccessTokenEntity);
|
$this->assertTrue($accessTokenProperty->getValue($entity) instanceof AccessTokenEntity);
|
||||||
@ -38,7 +51,7 @@ class RefreshTokenTest extends \PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
$accessTokenStorage = M::mock('League\OAuth2\Server\Storage\AccessTokenInterface');
|
$accessTokenStorage = M::mock('League\OAuth2\Server\Storage\AccessTokenInterface');
|
||||||
$accessTokenStorage->shouldReceive('setServer');
|
$accessTokenStorage->shouldReceive('setServer');
|
||||||
$accessTokenStorage->shouldReceive('getByRefreshToken')->andReturn(
|
$accessTokenStorage->shouldReceive('get')->andReturn(
|
||||||
(new AccessTokenEntity($server))->setId('foobar')
|
(new AccessTokenEntity($server))->setId('foobar')
|
||||||
);
|
);
|
||||||
$accessTokenStorage->shouldReceive('getScopes')->andReturn([
|
$accessTokenStorage->shouldReceive('getScopes')->andReturn([
|
||||||
|
Loading…
Reference in New Issue
Block a user