mirror of
https://github.com/elyby/oauth2-server.git
synced 2025-05-31 14:12:07 +05:30
Update associated scopes if requested in refresh access token. Fixes #47
This commit is contained in:
@@ -183,6 +183,7 @@ class Refresh_Token_test extends PHPUnit_Framework_TestCase
|
||||
$this->session->shouldReceive('updateRefreshToken')->andReturn(null);
|
||||
$this->session->shouldReceive('associateAccessToken')->andReturn(1);
|
||||
$this->session->shouldReceive('associateRefreshToken')->andReturn(1);
|
||||
$this->session->shouldReceive('removeRefreshToken')->andReturn(1);
|
||||
$this->session->shouldReceive('getAccessToken')->andReturn(null);
|
||||
$this->session->shouldReceive('getScopes')->andReturn(array());
|
||||
|
||||
@@ -226,6 +227,7 @@ class Refresh_Token_test extends PHPUnit_Framework_TestCase
|
||||
$this->session->shouldReceive('getScopes')->andReturn(array('id' => 1));
|
||||
$this->session->shouldReceive('associateAccessToken')->andReturn(1);
|
||||
$this->session->shouldReceive('associateRefreshToken')->andReturn(1);
|
||||
$this->session->shouldReceive('removeRefreshToken')->andReturn(1);
|
||||
$this->session->shouldReceive('associateScope')->andReturn(null);
|
||||
|
||||
$a = $this->returnDefault();
|
||||
@@ -265,6 +267,7 @@ class Refresh_Token_test extends PHPUnit_Framework_TestCase
|
||||
$this->session->shouldReceive('getScopes')->andReturn(array('id' => 1));
|
||||
$this->session->shouldReceive('associateAccessToken')->andReturn(1);
|
||||
$this->session->shouldReceive('associateRefreshToken')->andReturn(1);
|
||||
$this->session->shouldReceive('removeRefreshToken')->andReturn(1);
|
||||
$this->session->shouldReceive('associateScope')->andReturn(null);
|
||||
|
||||
$a = $this->returnDefault();
|
||||
@@ -290,4 +293,89 @@ class Refresh_Token_test extends PHPUnit_Framework_TestCase
|
||||
$this->assertEquals(30, $v['expires_in']);
|
||||
$this->assertEquals(time()+30, $v['expires']);
|
||||
}
|
||||
|
||||
public function test_issueAccessToken_refreshTokenGrant_newScopes()
|
||||
{
|
||||
$this->client->shouldReceive('getClient')->andReturn(array(
|
||||
'client_id' => 1234,
|
||||
'client_secret' => 5678,
|
||||
'redirect_uri' => 'http://foo/redirect',
|
||||
'name' => 'Example Client'
|
||||
));
|
||||
|
||||
$this->session->shouldReceive('validateRefreshToken')->andReturn(1);
|
||||
$this->session->shouldReceive('validateAuthCode')->andReturn(1);
|
||||
$this->session->shouldReceive('updateSession')->andReturn(null);
|
||||
$this->session->shouldReceive('updateRefreshToken')->andReturn(null);
|
||||
$this->session->shouldReceive('getAccessToken')->andReturn(null);
|
||||
$this->session->shouldReceive('getScopes')->andReturn(array(array('id' => 1, 'scope' => 'foo'), array('id' => 2, 'scope' => 'bar')));
|
||||
$this->session->shouldReceive('associateAccessToken')->andReturn(1);
|
||||
$this->session->shouldReceive('associateRefreshToken')->andReturn(1);
|
||||
$this->session->shouldReceive('removeRefreshToken')->andReturn(1);
|
||||
$this->session->shouldReceive('associateScope')->andReturn(null);
|
||||
$this->scope->shouldReceive('getScope')->andReturn(array('id' => 1, 'scope' => 'foo'));
|
||||
|
||||
$a = $this->returnDefault();
|
||||
$grant = new League\OAuth2\Server\Grant\RefreshToken($a);
|
||||
$grant->setAccessTokenTTL(30);
|
||||
$a->addGrantType($grant);
|
||||
|
||||
$v = $a->issueAccessToken(array(
|
||||
'grant_type' => 'refresh_token',
|
||||
'client_id' => 1234,
|
||||
'client_secret' => 5678,
|
||||
'refresh_token' => 'abcdef',
|
||||
'scope' => 'foo'
|
||||
));
|
||||
|
||||
$this->assertArrayHasKey('access_token', $v);
|
||||
$this->assertArrayHasKey('token_type', $v);
|
||||
$this->assertArrayHasKey('expires', $v);
|
||||
$this->assertArrayHasKey('expires_in', $v);
|
||||
$this->assertArrayHasKey('refresh_token', $v);
|
||||
|
||||
$this->assertNotEquals($a->getAccessTokenTTL(), $v['expires_in']);
|
||||
$this->assertNotEquals(time()+$a->getAccessTokenTTL(), $v['expires']);
|
||||
$this->assertEquals(30, $v['expires_in']);
|
||||
$this->assertEquals(time()+30, $v['expires']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException League\OAuth2\Server\Exception\ClientException
|
||||
* @expectedExceptionCode 0
|
||||
*/
|
||||
public function test_issueAccessToken_refreshTokenGrant_badNewScopes()
|
||||
{
|
||||
$this->client->shouldReceive('getClient')->andReturn(array(
|
||||
'client_id' => 1234,
|
||||
'client_secret' => 5678,
|
||||
'redirect_uri' => 'http://foo/redirect',
|
||||
'name' => 'Example Client'
|
||||
));
|
||||
|
||||
$this->session->shouldReceive('validateRefreshToken')->andReturn(1);
|
||||
$this->session->shouldReceive('validateAuthCode')->andReturn(1);
|
||||
$this->session->shouldReceive('updateSession')->andReturn(null);
|
||||
$this->session->shouldReceive('updateRefreshToken')->andReturn(null);
|
||||
$this->session->shouldReceive('getAccessToken')->andReturn(null);
|
||||
$this->session->shouldReceive('getScopes')->andReturn(array(array('id' => 1, 'scope' => 'foo'), array('id' => 2, 'scope' => 'bar')));
|
||||
$this->session->shouldReceive('associateAccessToken')->andReturn(1);
|
||||
$this->session->shouldReceive('associateRefreshToken')->andReturn(1);
|
||||
$this->session->shouldReceive('removeRefreshToken')->andReturn(1);
|
||||
$this->session->shouldReceive('associateScope')->andReturn(null);
|
||||
$this->scope->shouldReceive('getScope')->andReturn(array('id' => 1, 'scope' => 'foo'));
|
||||
|
||||
$a = $this->returnDefault();
|
||||
$grant = new League\OAuth2\Server\Grant\RefreshToken($a);
|
||||
$grant->setAccessTokenTTL(30);
|
||||
$a->addGrantType($grant);
|
||||
|
||||
$a->issueAccessToken(array(
|
||||
'grant_type' => 'refresh_token',
|
||||
'client_id' => 1234,
|
||||
'client_secret' => 5678,
|
||||
'refresh_token' => 'abcdef',
|
||||
'scope' => 'foobar'
|
||||
));
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user