From d6932cbb5e4de84fc6a692ccb6839174dfae643b Mon Sep 17 00:00:00 2001 From: Alex Bilbie Date: Wed, 8 May 2013 10:35:13 -0700 Subject: [PATCH] Renamed get/setExpiresIn to get/setAccessTokenTTL --- src/OAuth2/AuthServer.php | 8 +++--- src/OAuth2/Grant/AuthCode.php | 2 +- src/OAuth2/Grant/ClientCredentials.php | 2 +- src/OAuth2/Grant/Implicit.php | 2 +- src/OAuth2/Grant/Password.php | 2 +- src/OAuth2/Grant/RefreshToken.php | 2 +- tests/authorization/AuthServerTest.php | 26 +++++++++---------- .../ClientCredentialsGrantTest.php | 18 ++++++------- tests/authorization/PasswordGrantTest.php | 18 ++++++------- tests/authorization/RefreshTokenTest.php | 18 ++++++------- 10 files changed, 49 insertions(+), 49 deletions(-) diff --git a/src/OAuth2/AuthServer.php b/src/OAuth2/AuthServer.php index d49be227..fae8e9d0 100644 --- a/src/OAuth2/AuthServer.php +++ b/src/OAuth2/AuthServer.php @@ -37,7 +37,7 @@ class AuthServer * The TTL (time to live) of an access token in seconds (default: 3600) * @var integer */ - protected $expiresIn = 3600; + protected $accessTokenTTL = 3600; /** * The registered grant response types @@ -349,16 +349,16 @@ class AuthServer * Get the TTL for an access token * @return int The TTL */ - public function getExpiresIn() + public function getAccessTokenTTL() { - return $this->expiresIn; + return $this->accessTokenTTL; } /** * Set the TTL for an access token * @param int $accessTokenTTL The new TTL */ - public function setAcessTokenTTL($accessTokenTTL) + public function setAccessTokenTTL($accessTokenTTL) { $this->accessTokenTTL = $accessTokenTTL; } diff --git a/src/OAuth2/Grant/AuthCode.php b/src/OAuth2/Grant/AuthCode.php index 857ea842..733cb2b2 100644 --- a/src/OAuth2/Grant/AuthCode.php +++ b/src/OAuth2/Grant/AuthCode.php @@ -254,7 +254,7 @@ class AuthCode implements GrantTypeInterface { // A session ID was returned so update it with an access token and remove the authorisation code $accessToken = SecureKey::make(); - $accessTokenExpiresIn = ($this->accessTokenTTL !== null) ? $this->accessTokenTTL : $this->authServer->getExpiresIn(); + $accessTokenExpiresIn = ($this->accessTokenTTL !== null) ? $this->accessTokenTTL : $this->authServer->getAccessTokenTTL(); $accessTokenExpires = time() + $accessTokenExpiresIn; // Remove the auth code diff --git a/src/OAuth2/Grant/ClientCredentials.php b/src/OAuth2/Grant/ClientCredentials.php index 489bc5a5..38b63c9d 100644 --- a/src/OAuth2/Grant/ClientCredentials.php +++ b/src/OAuth2/Grant/ClientCredentials.php @@ -142,7 +142,7 @@ class ClientCredentials implements GrantTypeInterface { // Generate an access token $accessToken = SecureKey::make(); - $accessTokenExpiresIn = ($this->accessTokenTTL !== null) ? $this->accessTokenTTL : $this->authServer->getExpiresIn(); + $accessTokenExpiresIn = ($this->accessTokenTTL !== null) ? $this->accessTokenTTL : $this->authServer->getAccessTokenTTL(); $accessTokenExpires = time() + $accessTokenExpiresIn; // Delete any existing sessions just to be sure diff --git a/src/OAuth2/Grant/Implicit.php b/src/OAuth2/Grant/Implicit.php index 9ca9d611..defa2731 100644 --- a/src/OAuth2/Grant/Implicit.php +++ b/src/OAuth2/Grant/Implicit.php @@ -84,7 +84,7 @@ class Implict implements GrantTypeInterface { $accessToken = SecureKey::make(); // Compute expiry time - $accessTokenExpires = time() + $this->authServer->getExpiresIn(); + $accessTokenExpires = time() + $this->authServer->getAccessTokenTTL(); // Create a new session $sessionId = $this->authServer->getStorage('session')->createSession($authParams['client_id'], 'user', $authParams['user_id']); diff --git a/src/OAuth2/Grant/Password.php b/src/OAuth2/Grant/Password.php index 749a9526..4c706785 100644 --- a/src/OAuth2/Grant/Password.php +++ b/src/OAuth2/Grant/Password.php @@ -185,7 +185,7 @@ class Password implements GrantTypeInterface { // Generate an access token $accessToken = SecureKey::make(); - $accessTokenExpiresIn = ($this->accessTokenTTL !== null) ? $this->accessTokenTTL : $this->authServer->getExpiresIn(); + $accessTokenExpiresIn = ($this->accessTokenTTL !== null) ? $this->accessTokenTTL : $this->authServer->getAccessTokenTTL(); $accessTokenExpires = time() + $accessTokenExpiresIn; // Delete any existing sessions just to be sure diff --git a/src/OAuth2/Grant/RefreshToken.php b/src/OAuth2/Grant/RefreshToken.php index 130ddd2c..6e7a4efe 100644 --- a/src/OAuth2/Grant/RefreshToken.php +++ b/src/OAuth2/Grant/RefreshToken.php @@ -157,7 +157,7 @@ class RefreshToken implements GrantTypeInterface { // Generate new tokens and associate them to the session $accessToken = SecureKey::make(); - $accessTokenExpiresIn = ($this->accessTokenTTL !== null) ? $this->accessTokenTTL : $this->authServer->getExpiresIn(); + $accessTokenExpiresIn = ($this->accessTokenTTL !== null) ? $this->accessTokenTTL : $this->authServer->getAccessTokenTTL(); $accessTokenExpires = time() + $accessTokenExpiresIn; $refreshToken = SecureKey::make(); $refreshTokenExpires = time() + $this->getRefreshTokenTTL(); diff --git a/tests/authorization/AuthServerTest.php b/tests/authorization/AuthServerTest.php index 88f928b5..98216a20 100644 --- a/tests/authorization/AuthServerTest.php +++ b/tests/authorization/AuthServerTest.php @@ -152,14 +152,14 @@ class Authorization_Server_test extends PHPUnit_Framework_TestCase $this->assertTrue($v); } - public function test_getExpiresIn() + public function test_getAccessTokenTTL() { $a = $this->returnDefault(); - $a->setExpiresIn(7200); - $this->assertEquals(7200, $a->getExpiresIn()); + $a->setAccessTokenTTL(7200); + $this->assertEquals(7200, $a->getAccessTokenTTL()); } - public function test_setExpiresIn() + public function test_setAccessTokenTTL() { $a = $this->returnDefault(); $a->setScopeDelimeter(';'); @@ -382,8 +382,8 @@ class Authorization_Server_test extends PHPUnit_Framework_TestCase $this->assertArrayHasKey('expires', $v); $this->assertArrayHasKey('expires_in', $v); - $this->assertEquals($a->getExpiresIn(), $v['expires_in']); - $this->assertEquals(time()+$a->getExpiresIn(), $v['expires']); + $this->assertEquals($a->getAccessTokenTTL(), $v['expires_in']); + $this->assertEquals(time()+$a->getAccessTokenTTL(), $v['expires']); } public function test_issueAccessToken() @@ -419,8 +419,8 @@ class Authorization_Server_test extends PHPUnit_Framework_TestCase $this->assertArrayHasKey('expires', $v); $this->assertArrayHasKey('expires_in', $v); - $this->assertEquals($a->getExpiresIn(), $v['expires_in']); - $this->assertEquals(time()+$a->getExpiresIn(), $v['expires']); + $this->assertEquals($a->getAccessTokenTTL(), $v['expires_in']); + $this->assertEquals(time()+$a->getAccessTokenTTL(), $v['expires']); } public function test_issueAccessToken_customExpiresIn() @@ -439,7 +439,7 @@ class Authorization_Server_test extends PHPUnit_Framework_TestCase $a = $this->returnDefault(); $grant = new OAuth2\Grant\AuthCode($a); - $grant->setExpiresIn(30); + $grant->setAccessTokenTTL(30); $a->addGrantType($grant); $_POST['grant_type'] = 'authorization_code'; @@ -458,8 +458,8 @@ class Authorization_Server_test extends PHPUnit_Framework_TestCase $this->assertArrayHasKey('expires', $v); $this->assertArrayHasKey('expires_in', $v); - $this->assertNotEquals($a->getExpiresIn(), $v['expires_in']); - $this->assertNotEquals(time()+$a->getExpiresIn(), $v['expires']); + $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']); } @@ -497,8 +497,8 @@ class Authorization_Server_test extends PHPUnit_Framework_TestCase $this->assertArrayHasKey('expires', $v); $this->assertArrayHasKey('expires_in', $v); - $this->assertEquals($a->getExpiresIn(), $v['expires_in']); - $this->assertEquals(time()+$a->getExpiresIn(), $v['expires']); + $this->assertEquals($a->getAccessTokenTTL(), $v['expires_in']); + $this->assertEquals(time()+$a->getAccessTokenTTL(), $v['expires']); } public function tearDown() { diff --git a/tests/authorization/ClientCredentialsGrantTest.php b/tests/authorization/ClientCredentialsGrantTest.php index 679c54aa..ce6f7606 100644 --- a/tests/authorization/ClientCredentialsGrantTest.php +++ b/tests/authorization/ClientCredentialsGrantTest.php @@ -238,8 +238,8 @@ class Client_Credentials_Grant_Test extends PHPUnit_Framework_TestCase $this->assertArrayHasKey('expires', $v); $this->assertArrayHasKey('expires_in', $v); - $this->assertEquals($a->getExpiresIn(), $v['expires_in']); - $this->assertEquals(time()+$a->getExpiresIn(), $v['expires']); + $this->assertEquals($a->getAccessTokenTTL(), $v['expires_in']); + $this->assertEquals(time()+$a->getAccessTokenTTL(), $v['expires']); } function test_issueAccessToken_clientCredentialsGrant() @@ -276,8 +276,8 @@ class Client_Credentials_Grant_Test extends PHPUnit_Framework_TestCase $this->assertArrayHasKey('expires', $v); $this->assertArrayHasKey('expires_in', $v); - $this->assertEquals($a->getExpiresIn(), $v['expires_in']); - $this->assertEquals(time()+$a->getExpiresIn(), $v['expires']); + $this->assertEquals($a->getAccessTokenTTL(), $v['expires_in']); + $this->assertEquals(time()+$a->getAccessTokenTTL(), $v['expires']); } function test_issueAccessToken_clientCredentialsGrant_customExpiresIn() @@ -298,7 +298,7 @@ class Client_Credentials_Grant_Test extends PHPUnit_Framework_TestCase $a = $this->returnDefault(); $grant = new OAuth2\Grant\ClientCredentials($a); - $grant->setExpiresIn(30); + $grant->setAccessTokenTTL(30); $a->addGrantType($grant); $a->requireScopeParam(false); @@ -316,8 +316,8 @@ class Client_Credentials_Grant_Test extends PHPUnit_Framework_TestCase $this->assertArrayHasKey('expires', $v); $this->assertArrayHasKey('expires_in', $v); - $this->assertNotEquals($a->getExpiresIn(), $v['expires_in']); - $this->assertNotEquals(time()+$a->getExpiresIn(), $v['expires']); + $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']); } @@ -356,8 +356,8 @@ class Client_Credentials_Grant_Test extends PHPUnit_Framework_TestCase $this->assertArrayHasKey('expires', $v); $this->assertArrayHasKey('expires_in', $v); - $this->assertEquals($a->getExpiresIn(), $v['expires_in']); - $this->assertEquals(time()+$a->getExpiresIn(), $v['expires']); + $this->assertEquals($a->getAccessTokenTTL(), $v['expires_in']); + $this->assertEquals(time()+$a->getAccessTokenTTL(), $v['expires']); } } \ No newline at end of file diff --git a/tests/authorization/PasswordGrantTest.php b/tests/authorization/PasswordGrantTest.php index aee3005f..cee896e4 100644 --- a/tests/authorization/PasswordGrantTest.php +++ b/tests/authorization/PasswordGrantTest.php @@ -412,8 +412,8 @@ class Password_Grant_Test extends PHPUnit_Framework_TestCase $this->assertArrayHasKey('expires', $v); $this->assertArrayHasKey('expires_in', $v); - $this->assertEquals($a->getExpiresIn(), $v['expires_in']); - $this->assertEquals(time()+$a->getExpiresIn(), $v['expires']); + $this->assertEquals($a->getAccessTokenTTL(), $v['expires_in']); + $this->assertEquals(time()+$a->getAccessTokenTTL(), $v['expires']); } function test_issueAccessToken_passwordGrant() @@ -457,8 +457,8 @@ class Password_Grant_Test extends PHPUnit_Framework_TestCase $this->assertArrayHasKey('expires', $v); $this->assertArrayHasKey('expires_in', $v); - $this->assertEquals($a->getExpiresIn(), $v['expires_in']); - $this->assertEquals(time()+$a->getExpiresIn(), $v['expires']); + $this->assertEquals($a->getAccessTokenTTL(), $v['expires_in']); + $this->assertEquals(time()+$a->getAccessTokenTTL(), $v['expires']); } function test_issueAccessToken_passwordGrant_customExpiresIn() @@ -483,7 +483,7 @@ class Password_Grant_Test extends PHPUnit_Framework_TestCase $a = $this->returnDefault(); $pgrant = new OAuth2\Grant\Password($a); $pgrant->setVerifyCredentialsCallback($testCredentials); - $pgrant->setExpiresIn(30); + $pgrant->setAccessTokenTTL(30); $a->addGrantType($pgrant); $a->requireScopeParam(false); @@ -503,8 +503,8 @@ class Password_Grant_Test extends PHPUnit_Framework_TestCase $this->assertArrayHasKey('expires', $v); $this->assertArrayHasKey('expires_in', $v); - $this->assertNotEquals($a->getExpiresIn(), $v['expires_in']); - $this->assertNotEquals(time()+$a->getExpiresIn(), $v['expires']); + $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']); } @@ -552,8 +552,8 @@ class Password_Grant_Test extends PHPUnit_Framework_TestCase $this->assertArrayHasKey('expires_in', $v); $this->assertArrayHasKey('refresh_token', $v); - $this->assertEquals($a->getExpiresIn(), $v['expires_in']); - $this->assertEquals(time()+$a->getExpiresIn(), $v['expires']); + $this->assertEquals($a->getAccessTokenTTL(), $v['expires_in']); + $this->assertEquals(time()+$a->getAccessTokenTTL(), $v['expires']); } } \ No newline at end of file diff --git a/tests/authorization/RefreshTokenTest.php b/tests/authorization/RefreshTokenTest.php index b309638b..9d9c4ea0 100644 --- a/tests/authorization/RefreshTokenTest.php +++ b/tests/authorization/RefreshTokenTest.php @@ -56,8 +56,8 @@ class Refresh_Token_test extends PHPUnit_Framework_TestCase $this->assertArrayHasKey('expires_in', $v); $this->assertArrayHasKey('refresh_token', $v); - $this->assertEquals($a->getExpiresIn(), $v['expires_in']); - $this->assertEquals(time()+$a->getExpiresIn(), $v['expires']); + $this->assertEquals($a->getAccessTokenTTL(), $v['expires_in']); + $this->assertEquals(time()+$a->getAccessTokenTTL(), $v['expires']); } /** @@ -198,8 +198,8 @@ class Refresh_Token_test extends PHPUnit_Framework_TestCase $this->assertArrayHasKey('expires_in', $v); $this->assertArrayHasKey('refresh_token', $v); - $this->assertEquals($a->getExpiresIn(), $v['expires_in']); - $this->assertEquals(time()+$a->getExpiresIn(), $v['expires']); + $this->assertEquals($a->getAccessTokenTTL(), $v['expires_in']); + $this->assertEquals(time()+$a->getAccessTokenTTL(), $v['expires']); } public function test_issueAccessToken_refreshTokenGrant() @@ -237,8 +237,8 @@ class Refresh_Token_test extends PHPUnit_Framework_TestCase $this->assertArrayHasKey('expires_in', $v); $this->assertArrayHasKey('refresh_token', $v); - $this->assertEquals($a->getExpiresIn(), $v['expires_in']); - $this->assertEquals(time()+$a->getExpiresIn(), $v['expires']); + $this->assertEquals($a->getAccessTokenTTL(), $v['expires_in']); + $this->assertEquals(time()+$a->getAccessTokenTTL(), $v['expires']); } public function test_issueAccessToken_refreshTokenGrant_customExpiresIn() @@ -262,7 +262,7 @@ class Refresh_Token_test extends PHPUnit_Framework_TestCase $a = $this->returnDefault(); $grant = new OAuth2\Grant\RefreshToken($a); - $grant->setExpiresIn(30); + $grant->setAccessTokenTTL(30); $a->addGrantType($grant); $v = $a->issueAccessToken(array( @@ -278,8 +278,8 @@ class Refresh_Token_test extends PHPUnit_Framework_TestCase $this->assertArrayHasKey('expires_in', $v); $this->assertArrayHasKey('refresh_token', $v); - $this->assertNotEquals($a->getExpiresIn(), $v['expires_in']); - $this->assertNotEquals(time()+$a->getExpiresIn(), $v['expires']); + $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']); }