Skip to content

Commit

Permalink
adds tests and server integration for new refresh token config
Browse files Browse the repository at this point in the history
  • Loading branch information
bshaffer committed Apr 24, 2015
1 parent fd49216 commit cd648bc
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/OAuth2/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ public function __construct($storage = array(), array $config = array(), array $
'allow_credentials_in_request_body' => true,
'allow_public_clients' => true,
'always_issue_new_refresh_token' => false,
'unset_refresh_token_after_use' => true,
), $config);

foreach ($grantTypes as $key => $grantType) {
Expand Down Expand Up @@ -604,7 +605,7 @@ protected function getDefaultGrantTypes()
}

if (isset($this->storages['refresh_token'])) {
$config = array_intersect_key($this->config, array('always_issue_new_refresh_token' => ''));
$config = array_intersect_key($this->config, array_flip(explode(' ', 'always_issue_new_refresh_token unset_refresh_token_after_use')));
$grantTypes['refresh_token'] = new RefreshToken($this->storages['refresh_token'], $config);
}

Expand Down
21 changes: 21 additions & 0 deletions test/OAuth2/GrantType/RefreshTokenTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,27 @@ public function testValidRefreshTokenWithNewRefreshTokenInResponse()
$this->assertFalse($used_token, 'the refresh token used is no longer valid');
}

public function testValidRefreshTokenDoesNotUnsetToken()
{
$server = $this->getTestServer();
$server->addGrantType(new RefreshToken($this->storage, array(
'always_issue_new_refresh_token' => true,
'unset_refresh_token_after_use' => false,
)));

$request = TestRequest::createPost(array(
'grant_type' => 'refresh_token', // valid grant type
'client_id' => 'Test Client ID', // valid client id
'client_secret' => 'TestSecret', // valid client secret
'refresh_token' => 'test-refreshtoken', // valid refresh token
));
$token = $server->grantAccessToken($request, new Response());
$this->assertTrue(isset($token['refresh_token']), 'refresh token should always refresh');

$used_token = $this->storage->getRefreshToken('test-refreshtoken');
$this->assertNotNull($used_token, 'the refresh token used is still valid');
}

public function testValidRefreshTokenWithNoRefreshTokenInResponse()
{
$server = $this->getTestServer();
Expand Down
5 changes: 4 additions & 1 deletion test/OAuth2/ServerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ public function testRefreshTokenConfig()
// create mock storage
$storage = Bootstrap::getInstance()->getMemoryStorage();
$server1 = new Server(array($storage));
$server2 = new Server(array($storage), array('always_issue_new_refresh_token' => true));
$server2 = new Server(array($storage), array('always_issue_new_refresh_token' => true, 'unset_refresh_token_after_use' => false));

$server1->getTokenController();
$refreshToken1 = $server1->getGrantType('refresh_token');
Expand All @@ -386,6 +386,9 @@ public function testRefreshTokenConfig()

$this->assertEquals($config1['always_issue_new_refresh_token'], false);
$this->assertEquals($config2['always_issue_new_refresh_token'], true);

$this->assertEquals($config1['unset_refresh_token_after_use'], true);
$this->assertEquals($config2['unset_refresh_token_after_use'], false);
}

/**
Expand Down

0 comments on commit cd648bc

Please sign in to comment.