From 1419ba8cdcf18dd034c8db9f7de86a2594b68605 Mon Sep 17 00:00:00 2001 From: Phil Sturgeon Date: Wed, 4 Dec 2013 17:23:19 -0500 Subject: [PATCH 1/6] Added GrantTrait::setIdentifier I found it useful to be able to set the identifier so I could "alias" one for deprecation. Hopefully no issues here @alexbilbie --- src/League/OAuth2/Server/Grant/GrantTrait.php | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/League/OAuth2/Server/Grant/GrantTrait.php b/src/League/OAuth2/Server/Grant/GrantTrait.php index e052ce57..f444fa50 100644 --- a/src/League/OAuth2/Server/Grant/GrantTrait.php +++ b/src/League/OAuth2/Server/Grant/GrantTrait.php @@ -22,6 +22,17 @@ trait GrantTrait { return $this->identifier; } + /** + * Return the identifier + * @param string $identifier + * @return self + */ + public function setIdentifier($identifier) + { + $this->identifier = $identifier; + return $this; + } + /** * Return the response type * @return string @@ -42,4 +53,4 @@ trait GrantTrait { return $this; } -} \ No newline at end of file +} From 262ce23fb9c67feff9caa013d1ead78145371311 Mon Sep 17 00:00:00 2001 From: Alex Bilbie Date: Thu, 5 Dec 2013 20:25:50 +0000 Subject: [PATCH 2/6] No longer need to inject auth server into grant --- src/League/OAuth2/Server/Authorization.php | 4 +++ src/League/OAuth2/Server/Grant/AuthCode.php | 10 ------- .../OAuth2/Server/Grant/ClientCredentials.php | 10 ------- src/League/OAuth2/Server/Grant/GrantTrait.php | 29 +++++++++++++++++++ .../Server/Grant/GrantTypeInterface.php | 3 +- src/League/OAuth2/Server/Grant/Implicit.php | 10 ------- src/League/OAuth2/Server/Grant/Password.php | 10 ------- .../OAuth2/Server/Grant/RefreshToken.php | 10 ------- 8 files changed, 34 insertions(+), 52 deletions(-) diff --git a/src/League/OAuth2/Server/Authorization.php b/src/League/OAuth2/Server/Authorization.php index 4dec4695..c5d63d2e 100644 --- a/src/League/OAuth2/Server/Authorization.php +++ b/src/League/OAuth2/Server/Authorization.php @@ -244,6 +244,10 @@ class Authorization if (is_null($identifier)) { $identifier = $grantType->getIdentifier(); } + + // Inject server into grant + $grantType->setAuthorizationServer($this); + $this->grantTypes[$identifier] = $grantType; if ( ! is_null($grantType->getResponseType())) { diff --git a/src/League/OAuth2/Server/Grant/AuthCode.php b/src/League/OAuth2/Server/Grant/AuthCode.php index 79a541af..bf968980 100644 --- a/src/League/OAuth2/Server/Grant/AuthCode.php +++ b/src/League/OAuth2/Server/Grant/AuthCode.php @@ -56,16 +56,6 @@ class AuthCode implements GrantTypeInterface { */ protected $authTokenTTL = 600; - /** - * Constructor - * @param Authorization $authServer Authorization server instance - * @return void - */ - public function __construct(Authorization $authServer) - { - $this->authServer = $authServer; - } - /** * Override the default access token expire time * @param int $authTokenTTL diff --git a/src/League/OAuth2/Server/Grant/ClientCredentials.php b/src/League/OAuth2/Server/Grant/ClientCredentials.php index 4d53bf23..aa072d09 100644 --- a/src/League/OAuth2/Server/Grant/ClientCredentials.php +++ b/src/League/OAuth2/Server/Grant/ClientCredentials.php @@ -50,16 +50,6 @@ class ClientCredentials implements GrantTypeInterface { */ protected $accessTokenTTL = null; - /** - * Constructor - * @param Authorization $authServer Authorization server instance - * @return void - */ - public function __construct(Authorization $authServer) - { - $this->authServer = $authServer; - } - /** * Return the identifier * @return string diff --git a/src/League/OAuth2/Server/Grant/GrantTrait.php b/src/League/OAuth2/Server/Grant/GrantTrait.php index e052ce57..efbcf22f 100644 --- a/src/League/OAuth2/Server/Grant/GrantTrait.php +++ b/src/League/OAuth2/Server/Grant/GrantTrait.php @@ -11,8 +11,26 @@ namespace League\OAuth2\Server\Grant; +use League\OAuth2\Server\Authorization; + trait GrantTrait { + /** + * Constructor + * @param Authorization $authServer Authorization server instance + * @return void + */ + public function __construct(Authorization $authServer = null) + { + // @codeCoverageIgnoreStart + if ($authServer instanceof Authorization) { + trigger_error( + 'Server is now automatically injected into grant as of v3.1 of this library', + E_USER_DEPRECATED + ); + } // @codeCoverageIgnoreEnd + } + /** * Return the identifier * @return string @@ -42,4 +60,15 @@ trait GrantTrait { return $this; } + /** + * Inject the authorization server into the grant + * @param Authorization $authServer The authorization server instance + * @return self + */ + public function setAuthorizationServer(Authorization $authServer) + { + $this->authServer = $authServer; + return $this; + } + } \ No newline at end of file diff --git a/src/League/OAuth2/Server/Grant/GrantTypeInterface.php b/src/League/OAuth2/Server/Grant/GrantTypeInterface.php index ec0b906b..2301bd4e 100644 --- a/src/League/OAuth2/Server/Grant/GrantTypeInterface.php +++ b/src/League/OAuth2/Server/Grant/GrantTypeInterface.php @@ -23,10 +23,9 @@ interface GrantTypeInterface { /** * Constructor - * @param Authorization $authServer Authorization server instance * @return void */ - public function __construct(Authorization $authServer); + public function __construct(Authorization $authServer = null); /** * Complete the grant flow diff --git a/src/League/OAuth2/Server/Grant/Implicit.php b/src/League/OAuth2/Server/Grant/Implicit.php index a71afed5..a41c05a6 100644 --- a/src/League/OAuth2/Server/Grant/Implicit.php +++ b/src/League/OAuth2/Server/Grant/Implicit.php @@ -50,16 +50,6 @@ class Implicit implements GrantTypeInterface { */ protected $accessTokenTTL = null; - /** - * Constructor - * @param Authorization $authServer Authorization server instance - * @return void - */ - public function __construct(Authorization $authServer) - { - $this->authServer = $authServer; - } - /** * Complete the client credentials grant * @param null|array $inputParams diff --git a/src/League/OAuth2/Server/Grant/Password.php b/src/League/OAuth2/Server/Grant/Password.php index a81a62c3..54410586 100644 --- a/src/League/OAuth2/Server/Grant/Password.php +++ b/src/League/OAuth2/Server/Grant/Password.php @@ -56,16 +56,6 @@ class Password implements GrantTypeInterface { */ protected $accessTokenTTL = null; - /** - * Constructor - * @param Authorization $authServer Authorization server instance - * @return void - */ - public function __construct(Authorization $authServer) - { - $this->authServer = $authServer; - } - /** * Set the callback to verify a user's username and password * @param callable $callback The callback function diff --git a/src/League/OAuth2/Server/Grant/RefreshToken.php b/src/League/OAuth2/Server/Grant/RefreshToken.php index 4c4664f3..baea674a 100644 --- a/src/League/OAuth2/Server/Grant/RefreshToken.php +++ b/src/League/OAuth2/Server/Grant/RefreshToken.php @@ -62,16 +62,6 @@ class RefreshToken implements GrantTypeInterface { */ protected $rotateRefreshTokens = false; - /** - * Constructor - * @param Authorization $authServer Authorization server instance - * @return void - */ - public function __construct(Authorization $authServer) - { - $this->authServer = $authServer; - } - /** * Set the TTL of the refresh token * @param int $refreshTokenTTL From 0c360459133787f4162b5a48f70dd9d1f366c5ae Mon Sep 17 00:00:00 2001 From: Alex Bilbie Date: Thu, 5 Dec 2013 20:25:55 +0000 Subject: [PATCH 3/6] Updated unit tests --- tests/authorization/AuthCodeGrantTest.php | 49 +++++++++++-------- tests/authorization/AuthServerTest.php | 28 ++++++----- .../ClientCredentialsGrantTest.php | 24 ++++----- tests/authorization/PasswordGrantTest.php | 34 ++++++------- tests/authorization/RefreshTokenTest.php | 28 +++++------ 5 files changed, 87 insertions(+), 76 deletions(-) diff --git a/tests/authorization/AuthCodeGrantTest.php b/tests/authorization/AuthCodeGrantTest.php index ee6a5af9..43465e5b 100644 --- a/tests/authorization/AuthCodeGrantTest.php +++ b/tests/authorization/AuthCodeGrantTest.php @@ -20,10 +20,19 @@ class Auth_Code_Grant_Test extends PHPUnit_Framework_TestCase return new League\OAuth2\Server\Authorization($this->client, $this->session, $this->scope); } - public function test_setAuthTokenTTL() + /** + * @expectedException PHPUnit_Framework_Error + */ + public function test__construct() { $a = $this->returnDefault(); $grant = new League\OAuth2\Server\Grant\AuthCode($a); + } + + public function test_setAuthTokenTTL() + { + $a = $this->returnDefault(); + $grant = new League\OAuth2\Server\Grant\AuthCode(); $grant->setAuthTokenTTL(30); $reflector = new ReflectionClass($grant); @@ -41,7 +50,7 @@ class Auth_Code_Grant_Test extends PHPUnit_Framework_TestCase public function test_checkAuthoriseParams_noClientId() { $a = $this->returnDefault(); - $g = new League\OAuth2\Server\Grant\AuthCode($a); + $g = new League\OAuth2\Server\Grant\AuthCode(); $a->addGrantType($g); $g->checkAuthoriseParams(); } @@ -53,7 +62,7 @@ class Auth_Code_Grant_Test extends PHPUnit_Framework_TestCase public function test_checkAuthoriseParams_noRedirectUri() { $a = $this->returnDefault(); - $g = new League\OAuth2\Server\Grant\AuthCode($a); + $g = new League\OAuth2\Server\Grant\AuthCode(); $a->addGrantType($g); $g->checkAuthoriseParams(array( 'client_id' => 1234 @@ -67,7 +76,7 @@ class Auth_Code_Grant_Test extends PHPUnit_Framework_TestCase public function test_checkAuthoriseParams_noRequiredState() { $a = $this->returnDefault(); - $g = new League\OAuth2\Server\Grant\AuthCode($a); + $g = new League\OAuth2\Server\Grant\AuthCode(); $a->addGrantType($g); $a->requireStateParam(true); $g->checkAuthoriseParams(array( @@ -86,7 +95,7 @@ class Auth_Code_Grant_Test extends PHPUnit_Framework_TestCase $this->client->shouldReceive('getClient')->andReturn(false); $a = $this->returnDefault(); - $g = new League\OAuth2\Server\Grant\AuthCode($a); + $g = new League\OAuth2\Server\Grant\AuthCode(); $a->addGrantType($g); $g->checkAuthoriseParams(array( 'client_id' => 1234, @@ -108,7 +117,7 @@ class Auth_Code_Grant_Test extends PHPUnit_Framework_TestCase )); $a = $this->returnDefault(); - $g = new League\OAuth2\Server\Grant\AuthCode($a); + $g = new League\OAuth2\Server\Grant\AuthCode(); $a->addGrantType($g); $g->checkAuthoriseParams(array( 'client_id' => 1234, @@ -130,7 +139,7 @@ class Auth_Code_Grant_Test extends PHPUnit_Framework_TestCase )); $a = $this->returnDefault(); - $g = new League\OAuth2\Server\Grant\AuthCode($a); + $g = new League\OAuth2\Server\Grant\AuthCode(); $a->addGrantType($g); $g->checkAuthoriseParams(array( 'client_id' => 1234, @@ -153,9 +162,9 @@ class Auth_Code_Grant_Test extends PHPUnit_Framework_TestCase )); $a = $this->returnDefault(); - $g = new League\OAuth2\Server\Grant\AuthCode($a); + $g = new League\OAuth2\Server\Grant\AuthCode(); $a->addGrantType($g); - $a->addGrantType(new League\OAuth2\Server\Grant\AuthCode($a)); + $a->addGrantType(new League\OAuth2\Server\Grant\AuthCode()); $a->requireScopeParam(true); $g->checkAuthoriseParams(array( @@ -183,9 +192,9 @@ class Auth_Code_Grant_Test extends PHPUnit_Framework_TestCase )); $a = $this->returnDefault(); - $g = new League\OAuth2\Server\Grant\AuthCode($a); + $g = new League\OAuth2\Server\Grant\AuthCode(); $a->addGrantType($g); - $a->addGrantType(new League\OAuth2\Server\Grant\AuthCode($a)); + $a->addGrantType(new League\OAuth2\Server\Grant\AuthCode()); $a->setDefaultScope('test.scope'); $a->requireScopeParam(false); @@ -217,9 +226,9 @@ class Auth_Code_Grant_Test extends PHPUnit_Framework_TestCase )); $a = $this->returnDefault(); - $g = new League\OAuth2\Server\Grant\AuthCode($a); + $g = new League\OAuth2\Server\Grant\AuthCode(); $a->addGrantType($g); - $a->addGrantType(new League\OAuth2\Server\Grant\AuthCode($a)); + $a->addGrantType(new League\OAuth2\Server\Grant\AuthCode()); $a->setDefaultScope(array('test.scope', 'test.scope2')); $a->requireScopeParam(false); @@ -250,9 +259,9 @@ class Auth_Code_Grant_Test extends PHPUnit_Framework_TestCase $this->scope->shouldReceive('getScope')->andReturn(false); $a = $this->returnDefault(); - $g = new League\OAuth2\Server\Grant\AuthCode($a); + $g = new League\OAuth2\Server\Grant\AuthCode(); $a->addGrantType($g); - $a->addGrantType(new League\OAuth2\Server\Grant\AuthCode($a)); + $a->addGrantType(new League\OAuth2\Server\Grant\AuthCode()); $g->checkAuthoriseParams(array( 'client_id' => 1234, @@ -265,9 +274,9 @@ class Auth_Code_Grant_Test extends PHPUnit_Framework_TestCase public function test_checkAuthoriseParams_passedInput() { $a = $this->returnDefault(); - $g = new League\OAuth2\Server\Grant\AuthCode($a); + $g = new League\OAuth2\Server\Grant\AuthCode(); $a->addGrantType($g); - $a->addGrantType(new League\OAuth2\Server\Grant\AuthCode($a)); + $a->addGrantType(new League\OAuth2\Server\Grant\AuthCode()); $this->client->shouldReceive('getClient')->andReturn(array( 'client_id' => 1234, @@ -331,9 +340,9 @@ class Auth_Code_Grant_Test extends PHPUnit_Framework_TestCase )); $a = $this->returnDefault(); - $g = new League\OAuth2\Server\Grant\AuthCode($a); + $g = new League\OAuth2\Server\Grant\AuthCode(); $a->addGrantType($g); - $a->addGrantType(new League\OAuth2\Server\Grant\AuthCode($a)); + $a->addGrantType(new League\OAuth2\Server\Grant\AuthCode()); $_GET['client_id'] = 1234; $_GET['redirect_uri'] = 'http://foo/redirect'; @@ -380,7 +389,7 @@ class Auth_Code_Grant_Test extends PHPUnit_Framework_TestCase $this->session->shouldReceive('associateAuthCodeScope')->andReturn(null); $a = $this->returnDefault(); - $g = new League\OAuth2\Server\Grant\AuthCode($a); + $g = new League\OAuth2\Server\Grant\AuthCode(); $a->addGrantType($g); $params = array( diff --git a/tests/authorization/AuthServerTest.php b/tests/authorization/AuthServerTest.php index f4bd2db4..e73184be 100644 --- a/tests/authorization/AuthServerTest.php +++ b/tests/authorization/AuthServerTest.php @@ -69,6 +69,7 @@ class Authorization_Server_test extends PHPUnit_Framework_TestCase $a = $this->returnDefault(); $grant = M::mock('League\OAuth2\Server\Grant\GrantTypeInterface'); $grant->shouldReceive('getResponseType')->andReturn('test'); + $grant->shouldReceive('setAuthorizationServer')->andReturn($grant); $a->addGrantType($grant, 'test'); $this->assertTrue($a->hasGrantType('test')); @@ -80,6 +81,7 @@ class Authorization_Server_test extends PHPUnit_Framework_TestCase $grant = M::mock('League\OAuth2\Server\Grant\GrantTypeInterface'); $grant->shouldReceive('getIdentifier')->andReturn('test'); $grant->shouldReceive('getResponseType')->andReturn('test'); + $grant->shouldReceive('setAuthorizationServer')->andReturn($grant); $a->addGrantType($grant); $this->assertTrue($a->hasGrantType('test')); @@ -199,7 +201,7 @@ class Authorization_Server_test extends PHPUnit_Framework_TestCase public function test_getGrantType() { $a = $this->returnDefault(); - $a->addGrantType(new League\OAuth2\Server\Grant\AuthCode($a)); + $a->addGrantType(new League\OAuth2\Server\Grant\AuthCode()); $reflector = new ReflectionClass($a); $method = $reflector->getMethod('getGrantType'); @@ -227,7 +229,7 @@ class Authorization_Server_test extends PHPUnit_Framework_TestCase public function test_issueAccessToken_missingGrantType() { $a = $this->returnDefault(); - $a->addGrantType(new League\OAuth2\Server\Grant\AuthCode($a)); + $a->addGrantType(new League\OAuth2\Server\Grant\AuthCode()); $a->issueAccessToken(); } @@ -239,7 +241,7 @@ class Authorization_Server_test extends PHPUnit_Framework_TestCase public function test_issueAccessToken_badGrantType() { $a = $this->returnDefault(); - $a->addGrantType(new League\OAuth2\Server\Grant\AuthCode($a)); + $a->addGrantType(new League\OAuth2\Server\Grant\AuthCode()); $a->issueAccessToken(array('grant_type' => 'foo')); } @@ -251,7 +253,7 @@ class Authorization_Server_test extends PHPUnit_Framework_TestCase public function test_issueAccessToken_missingClientId() { $a = $this->returnDefault(); - $a->addGrantType(new League\OAuth2\Server\Grant\AuthCode($a)); + $a->addGrantType(new League\OAuth2\Server\Grant\AuthCode()); $a->issueAccessToken(array( 'grant_type' => 'authorization_code' @@ -265,7 +267,7 @@ class Authorization_Server_test extends PHPUnit_Framework_TestCase public function test_issueAccessToken_missingClientSecret() { $a = $this->returnDefault(); - $a->addGrantType(new League\OAuth2\Server\Grant\AuthCode($a)); + $a->addGrantType(new League\OAuth2\Server\Grant\AuthCode()); $a->issueAccessToken(array( 'grant_type' => 'authorization_code', @@ -280,7 +282,7 @@ class Authorization_Server_test extends PHPUnit_Framework_TestCase public function test_issueAccessToken_missingRedirectUri() { $a = $this->returnDefault(); - $a->addGrantType(new League\OAuth2\Server\Grant\AuthCode($a)); + $a->addGrantType(new League\OAuth2\Server\Grant\AuthCode()); $a->issueAccessToken(array( 'grant_type' => 'authorization_code', @@ -298,7 +300,7 @@ class Authorization_Server_test extends PHPUnit_Framework_TestCase $this->client->shouldReceive('getClient')->andReturn(false); $a = $this->returnDefault(); - $a->addGrantType(new League\OAuth2\Server\Grant\AuthCode($a)); + $a->addGrantType(new League\OAuth2\Server\Grant\AuthCode()); $a->issueAccessToken(array( 'grant_type' => 'authorization_code', @@ -317,7 +319,7 @@ class Authorization_Server_test extends PHPUnit_Framework_TestCase $this->client->shouldReceive('getClient')->andReturn(array()); $a = $this->returnDefault(); - $a->addGrantType(new League\OAuth2\Server\Grant\AuthCode($a)); + $a->addGrantType(new League\OAuth2\Server\Grant\AuthCode()); $a->issueAccessToken(array( 'grant_type' => 'authorization_code', @@ -337,7 +339,7 @@ class Authorization_Server_test extends PHPUnit_Framework_TestCase $this->session->shouldReceive('validateAuthCode')->andReturn(false); $a = $this->returnDefault(); - $a->addGrantType(new League\OAuth2\Server\Grant\AuthCode($a)); + $a->addGrantType(new League\OAuth2\Server\Grant\AuthCode()); $a->issueAccessToken(array( 'grant_type' => 'authorization_code', @@ -368,7 +370,7 @@ class Authorization_Server_test extends PHPUnit_Framework_TestCase $this->session->shouldReceive('getAuthCodeScopes')->andReturn(array('scope_id' => 1)); $a = $this->returnDefault(); - $a->addGrantType(new League\OAuth2\Server\Grant\AuthCode($a)); + $a->addGrantType(new League\OAuth2\Server\Grant\AuthCode()); $v = $a->issueAccessToken(array( 'grant_type' => 'authorization_code', @@ -404,7 +406,7 @@ class Authorization_Server_test extends PHPUnit_Framework_TestCase $this->session->shouldReceive('associateScope')->andReturn(null); $a = $this->returnDefault(); - $a->addGrantType(new League\OAuth2\Server\Grant\AuthCode($a)); + $a->addGrantType(new League\OAuth2\Server\Grant\AuthCode()); $_POST['grant_type'] = 'authorization_code'; $_POST['client_id'] = 1234; @@ -443,7 +445,7 @@ class Authorization_Server_test extends PHPUnit_Framework_TestCase $this->session->shouldReceive('associateScope')->andReturn(null); $a = $this->returnDefault(); - $grant = new League\OAuth2\Server\Grant\AuthCode($a); + $grant = new League\OAuth2\Server\Grant\AuthCode(); $grant->setAccessTokenTTL(30); $a->addGrantType($grant); @@ -486,7 +488,7 @@ class Authorization_Server_test extends PHPUnit_Framework_TestCase $this->session->shouldReceive('associateScope')->andReturn(null); $a = $this->returnDefault(); - $a->addGrantType(new League\OAuth2\Server\Grant\AuthCode($a)); + $a->addGrantType(new League\OAuth2\Server\Grant\AuthCode()); $_POST['grant_type'] = 'authorization_code'; $_SERVER['PHP_AUTH_USER'] = 1234; diff --git a/tests/authorization/ClientCredentialsGrantTest.php b/tests/authorization/ClientCredentialsGrantTest.php index 753c73e5..bb312690 100644 --- a/tests/authorization/ClientCredentialsGrantTest.php +++ b/tests/authorization/ClientCredentialsGrantTest.php @@ -27,7 +27,7 @@ class Client_Credentials_Grant_Test extends PHPUnit_Framework_TestCase public function test_issueAccessToken_clientCredentialsGrant_missingClientId() { $a = $this->returnDefault(); - $a->addGrantType(new League\OAuth2\Server\Grant\ClientCredentials($a)); + $a->addGrantType(new League\OAuth2\Server\Grant\ClientCredentials()); $request = new League\OAuth2\Server\Util\Request(array(), $_POST); $a->setRequest($request); @@ -44,7 +44,7 @@ class Client_Credentials_Grant_Test extends PHPUnit_Framework_TestCase public function test_issueAccessToken_clientCredentialsGrant_missingClientPassword() { $a = $this->returnDefault(); - $a->addGrantType(new League\OAuth2\Server\Grant\ClientCredentials($a)); + $a->addGrantType(new League\OAuth2\Server\Grant\ClientCredentials()); $request = new League\OAuth2\Server\Util\Request(array(), $_POST); $a->setRequest($request); @@ -64,7 +64,7 @@ class Client_Credentials_Grant_Test extends PHPUnit_Framework_TestCase $this->client->shouldReceive('getClient')->andReturn(false); $a = $this->returnDefault(); - $a->addGrantType(new League\OAuth2\Server\Grant\ClientCredentials($a)); + $a->addGrantType(new League\OAuth2\Server\Grant\ClientCredentials()); $request = new League\OAuth2\Server\Util\Request(array(), $_POST); $a->setRequest($request); @@ -95,7 +95,7 @@ class Client_Credentials_Grant_Test extends PHPUnit_Framework_TestCase $this->session->shouldReceive('deleteSession')->andReturn(null); $a = $this->returnDefault(); - $a->addGrantType(new League\OAuth2\Server\Grant\ClientCredentials($a)); + $a->addGrantType(new League\OAuth2\Server\Grant\ClientCredentials()); $a->requireScopeParam(true); $a->issueAccessToken(array( @@ -129,7 +129,7 @@ class Client_Credentials_Grant_Test extends PHPUnit_Framework_TestCase $this->session->shouldReceive('associateAccessToken')->andReturn(1); $a = $this->returnDefault(); - $a->addGrantType(new League\OAuth2\Server\Grant\ClientCredentials($a)); + $a->addGrantType(new League\OAuth2\Server\Grant\ClientCredentials()); $a->requireScopeParam(false); $a->setDefaultScope('foobar'); @@ -170,7 +170,7 @@ class Client_Credentials_Grant_Test extends PHPUnit_Framework_TestCase $this->session->shouldReceive('associateAccessToken')->andReturn(1); $a = $this->returnDefault(); - $a->addGrantType(new League\OAuth2\Server\Grant\ClientCredentials($a)); + $a->addGrantType(new League\OAuth2\Server\Grant\ClientCredentials()); $a->requireScopeParam(false); $a->setDefaultScope(array('foobar', 'barfoo')); @@ -209,7 +209,7 @@ class Client_Credentials_Grant_Test extends PHPUnit_Framework_TestCase $this->session->shouldReceive('associateScope')->andReturn(null); $a = $this->returnDefault(); - $a->addGrantType(new League\OAuth2\Server\Grant\ClientCredentials($a)); + $a->addGrantType(new League\OAuth2\Server\Grant\ClientCredentials()); $a->issueAccessToken(array( 'grant_type' => 'client_credentials', @@ -243,7 +243,7 @@ class Client_Credentials_Grant_Test extends PHPUnit_Framework_TestCase $this->session->shouldReceive('associateAccessToken')->andReturn(1); $a = $this->returnDefault(); - $a->addGrantType(new League\OAuth2\Server\Grant\ClientCredentials($a)); + $a->addGrantType(new League\OAuth2\Server\Grant\ClientCredentials()); $v = $a->issueAccessToken(array( 'grant_type' => 'client_credentials', @@ -275,7 +275,7 @@ class Client_Credentials_Grant_Test extends PHPUnit_Framework_TestCase $this->session->shouldReceive('associateAccessToken')->andReturn(1); $a = $this->returnDefault(); - $a->addGrantType(new League\OAuth2\Server\Grant\ClientCredentials($a)); + $a->addGrantType(new League\OAuth2\Server\Grant\ClientCredentials()); $a->requireScopeParam(false); $v = $a->issueAccessToken(array( @@ -310,7 +310,7 @@ class Client_Credentials_Grant_Test extends PHPUnit_Framework_TestCase $this->session->shouldReceive('associateAccessToken')->andReturn(1); $a = $this->returnDefault(); - $a->addGrantType(new League\OAuth2\Server\Grant\ClientCredentials($a)); + $a->addGrantType(new League\OAuth2\Server\Grant\ClientCredentials()); $a->requireScopeParam(false); $_POST['grant_type'] = 'client_credentials'; @@ -348,7 +348,7 @@ class Client_Credentials_Grant_Test extends PHPUnit_Framework_TestCase $this->session->shouldReceive('associateAccessToken')->andReturn(1); $a = $this->returnDefault(); - $grant = new League\OAuth2\Server\Grant\ClientCredentials($a); + $grant = new League\OAuth2\Server\Grant\ClientCredentials(); $grant->setAccessTokenTTL(30); $a->addGrantType($grant); $a->requireScopeParam(false); @@ -390,7 +390,7 @@ class Client_Credentials_Grant_Test extends PHPUnit_Framework_TestCase $this->session->shouldReceive('associateAccessToken')->andReturn(1); $a = $this->returnDefault(); - $a->addGrantType(new League\OAuth2\Server\Grant\ClientCredentials($a)); + $a->addGrantType(new League\OAuth2\Server\Grant\ClientCredentials()); $a->requireScopeParam(false); $_POST['grant_type'] = 'client_credentials'; diff --git a/tests/authorization/PasswordGrantTest.php b/tests/authorization/PasswordGrantTest.php index a73054f8..71d2cec3 100644 --- a/tests/authorization/PasswordGrantTest.php +++ b/tests/authorization/PasswordGrantTest.php @@ -27,7 +27,7 @@ class Password_Grant_Test extends PHPUnit_Framework_TestCase public function test_issueAccessToken_passwordGrant_missingClientId() { $a = $this->returnDefault(); - $a->addGrantType(new League\OAuth2\Server\Grant\Password($a)); + $a->addGrantType(new League\OAuth2\Server\Grant\Password()); $request = new League\OAuth2\Server\Util\Request(array(), $_POST); $a->setRequest($request); @@ -44,7 +44,7 @@ class Password_Grant_Test extends PHPUnit_Framework_TestCase public function test_issueAccessToken_passwordGrant_missingClientPassword() { $a = $this->returnDefault(); - $a->addGrantType(new League\OAuth2\Server\Grant\Password($a)); + $a->addGrantType(new League\OAuth2\Server\Grant\Password()); $request = new League\OAuth2\Server\Util\Request(array(), $_POST); $a->setRequest($request); @@ -64,7 +64,7 @@ class Password_Grant_Test extends PHPUnit_Framework_TestCase $this->client->shouldReceive('getClient')->andReturn(false); $a = $this->returnDefault(); - $a->addGrantType(new League\OAuth2\Server\Grant\Password($a)); + $a->addGrantType(new League\OAuth2\Server\Grant\Password()); $request = new League\OAuth2\Server\Util\Request(array(), $_POST); $a->setRequest($request); @@ -98,7 +98,7 @@ class Password_Grant_Test extends PHPUnit_Framework_TestCase $testCredentials = null; $a = $this->returnDefault(); - $pgrant = new League\OAuth2\Server\Grant\Password($a); + $pgrant = new League\OAuth2\Server\Grant\Password(); $pgrant->setVerifyCredentialsCallback($testCredentials); $a->addGrantType($pgrant); @@ -134,7 +134,7 @@ class Password_Grant_Test extends PHPUnit_Framework_TestCase $testCredentials = function() { return false; }; $a = $this->returnDefault(); - $pgrant = new League\OAuth2\Server\Grant\Password($a); + $pgrant = new League\OAuth2\Server\Grant\Password(); $pgrant->setVerifyCredentialsCallback($testCredentials); $a->addGrantType($pgrant); @@ -168,7 +168,7 @@ class Password_Grant_Test extends PHPUnit_Framework_TestCase $testCredentials = function() { return false; }; $a = $this->returnDefault(); - $pgrant = new League\OAuth2\Server\Grant\Password($a); + $pgrant = new League\OAuth2\Server\Grant\Password(); $pgrant->setVerifyCredentialsCallback($testCredentials); $a->addGrantType($pgrant); @@ -203,7 +203,7 @@ class Password_Grant_Test extends PHPUnit_Framework_TestCase $testCredentials = function() { return false; }; $a = $this->returnDefault(); - $pgrant = new League\OAuth2\Server\Grant\Password($a); + $pgrant = new League\OAuth2\Server\Grant\Password(); $pgrant->setVerifyCredentialsCallback($testCredentials); $a->addGrantType($pgrant); @@ -240,7 +240,7 @@ class Password_Grant_Test extends PHPUnit_Framework_TestCase $testCredentials = function() { return 1; }; $a = $this->returnDefault(); - $pgrant = new League\OAuth2\Server\Grant\Password($a); + $pgrant = new League\OAuth2\Server\Grant\Password(); $pgrant->setVerifyCredentialsCallback($testCredentials); $a->addGrantType($pgrant); @@ -276,7 +276,7 @@ class Password_Grant_Test extends PHPUnit_Framework_TestCase $testCredentials = function() { return 1; }; $a = $this->returnDefault(); - $pgrant = new League\OAuth2\Server\Grant\Password($a); + $pgrant = new League\OAuth2\Server\Grant\Password(); $pgrant->setVerifyCredentialsCallback($testCredentials); $a->addGrantType($pgrant); $a->requireScopeParam(true); @@ -317,7 +317,7 @@ class Password_Grant_Test extends PHPUnit_Framework_TestCase $testCredentials = function() { return 1; }; $a = $this->returnDefault(); - $pgrant = new League\OAuth2\Server\Grant\Password($a); + $pgrant = new League\OAuth2\Server\Grant\Password(); $pgrant->setVerifyCredentialsCallback($testCredentials); $a->addGrantType($pgrant); $a->requireScopeParam(false); @@ -365,7 +365,7 @@ class Password_Grant_Test extends PHPUnit_Framework_TestCase $testCredentials = function() { return 1; }; $a = $this->returnDefault(); - $pgrant = new League\OAuth2\Server\Grant\Password($a); + $pgrant = new League\OAuth2\Server\Grant\Password(); $pgrant->setVerifyCredentialsCallback($testCredentials); $a->addGrantType($pgrant); $a->requireScopeParam(false); @@ -413,7 +413,7 @@ class Password_Grant_Test extends PHPUnit_Framework_TestCase $testCredentials = function() { return 1; }; $a = $this->returnDefault(); - $pgrant = new League\OAuth2\Server\Grant\Password($a); + $pgrant = new League\OAuth2\Server\Grant\Password(); $pgrant->setVerifyCredentialsCallback($testCredentials); $a->addGrantType($pgrant); @@ -452,7 +452,7 @@ class Password_Grant_Test extends PHPUnit_Framework_TestCase $testCredentials = function() { return 1; }; $a = $this->returnDefault(); - $pgrant = new League\OAuth2\Server\Grant\Password($a); + $pgrant = new League\OAuth2\Server\Grant\Password(); $pgrant->setVerifyCredentialsCallback($testCredentials); $a->addGrantType($pgrant); $a->requireScopeParam(false); @@ -494,7 +494,7 @@ class Password_Grant_Test extends PHPUnit_Framework_TestCase $testCredentials = function() { return 1; }; $a = $this->returnDefault(); - $pgrant = new League\OAuth2\Server\Grant\Password($a); + $pgrant = new League\OAuth2\Server\Grant\Password(); $pgrant->setVerifyCredentialsCallback($testCredentials); $a->addGrantType($pgrant); $a->requireScopeParam(false); @@ -539,7 +539,7 @@ class Password_Grant_Test extends PHPUnit_Framework_TestCase $testCredentials = function() { return 1; }; $a = $this->returnDefault(); - $pgrant = new League\OAuth2\Server\Grant\Password($a); + $pgrant = new League\OAuth2\Server\Grant\Password(); $pgrant->setVerifyCredentialsCallback($testCredentials); $pgrant->setAccessTokenTTL(30); $a->addGrantType($pgrant); @@ -587,10 +587,10 @@ class Password_Grant_Test extends PHPUnit_Framework_TestCase $testCredentials = function() { return 1; }; $a = $this->returnDefault(); - $pgrant = new League\OAuth2\Server\Grant\Password($a); + $pgrant = new League\OAuth2\Server\Grant\Password(); $pgrant->setVerifyCredentialsCallback($testCredentials); $a->addGrantType($pgrant); - $a->addGrantType(new League\OAuth2\Server\Grant\RefreshToken($a)); + $a->addGrantType(new League\OAuth2\Server\Grant\RefreshToken()); $a->requireScopeParam(false); $_POST['grant_type'] = 'password'; diff --git a/tests/authorization/RefreshTokenTest.php b/tests/authorization/RefreshTokenTest.php index f4882454..290169e3 100644 --- a/tests/authorization/RefreshTokenTest.php +++ b/tests/authorization/RefreshTokenTest.php @@ -23,7 +23,7 @@ class Refresh_Token_test extends PHPUnit_Framework_TestCase public function test_setRefreshTokenTTL() { $a = $this->returnDefault(); - $rt = new League\OAuth2\Server\Grant\RefreshToken($a); + $rt = new League\OAuth2\Server\Grant\RefreshToken(); $rt->setRefreshTokenTTL(30); $this->assertEquals(30, $rt->getRefreshTokenTTL()); } @@ -46,8 +46,8 @@ class Refresh_Token_test extends PHPUnit_Framework_TestCase $this->session->shouldReceive('getAuthCodeScopes')->andReturn(array('scope_id' => 1)); $a = $this->returnDefault(); - $a->addGrantType(new League\OAuth2\Server\Grant\AuthCode($a)); - $a->addGrantType(new League\OAuth2\Server\Grant\RefreshToken($a)); + $a->addGrantType(new League\OAuth2\Server\Grant\AuthCode()); + $a->addGrantType(new League\OAuth2\Server\Grant\RefreshToken()); $_POST['grant_type'] = 'authorization_code'; $_POST['client_id'] = 1234; @@ -77,7 +77,7 @@ class Refresh_Token_test extends PHPUnit_Framework_TestCase public function test_issueAccessToken_refreshTokenGrant_missingClientId() { $a = $this->returnDefault(); - $a->addGrantType(new League\OAuth2\Server\Grant\RefreshToken($a)); + $a->addGrantType(new League\OAuth2\Server\Grant\RefreshToken()); $request = new League\OAuth2\Server\Util\Request(array(), $_POST); $a->setRequest($request); @@ -94,7 +94,7 @@ class Refresh_Token_test extends PHPUnit_Framework_TestCase public function test_issueAccessToken_refreshTokenGrant_missingClientSecret() { $a = $this->returnDefault(); - $a->addGrantType(new League\OAuth2\Server\Grant\RefreshToken($a)); + $a->addGrantType(new League\OAuth2\Server\Grant\RefreshToken()); $request = new League\OAuth2\Server\Util\Request(array(), $_POST); $a->setRequest($request); @@ -114,7 +114,7 @@ class Refresh_Token_test extends PHPUnit_Framework_TestCase $this->client->shouldReceive('getClient')->andReturn(false); $a = $this->returnDefault(); - $a->addGrantType(new League\OAuth2\Server\Grant\RefreshToken($a)); + $a->addGrantType(new League\OAuth2\Server\Grant\RefreshToken()); $request = new League\OAuth2\Server\Util\Request(array(), $_POST); $a->setRequest($request); @@ -135,7 +135,7 @@ class Refresh_Token_test extends PHPUnit_Framework_TestCase $this->client->shouldReceive('getClient')->andReturn(array()); $a = $this->returnDefault(); - $a->addGrantType(new League\OAuth2\Server\Grant\RefreshToken($a)); + $a->addGrantType(new League\OAuth2\Server\Grant\RefreshToken()); $request = new League\OAuth2\Server\Util\Request(array(), $_POST); $a->setRequest($request); @@ -157,7 +157,7 @@ class Refresh_Token_test extends PHPUnit_Framework_TestCase $this->session->shouldReceive('validateRefreshToken')->andReturn(false); $a = $this->returnDefault(); - $a->addGrantType(new League\OAuth2\Server\Grant\RefreshToken($a)); + $a->addGrantType(new League\OAuth2\Server\Grant\RefreshToken()); $request = new League\OAuth2\Server\Util\Request(array(), $_POST); $a->setRequest($request); @@ -190,7 +190,7 @@ class Refresh_Token_test extends PHPUnit_Framework_TestCase $this->session->shouldReceive('getScopes')->andReturn(array()); $a = $this->returnDefault(); - $a->addGrantType(new League\OAuth2\Server\Grant\RefreshToken($a)); + $a->addGrantType(new League\OAuth2\Server\Grant\RefreshToken()); $_POST['grant_type'] = 'refresh_token'; $_POST['client_id'] = 1234; @@ -232,7 +232,7 @@ class Refresh_Token_test extends PHPUnit_Framework_TestCase $this->session->shouldReceive('associateScope')->andReturn(null); $a = $this->returnDefault(); - $a->addGrantType(new League\OAuth2\Server\Grant\RefreshToken($a)); + $a->addGrantType(new League\OAuth2\Server\Grant\RefreshToken()); $v = $a->issueAccessToken(array( 'grant_type' => 'refresh_token', @@ -272,7 +272,7 @@ class Refresh_Token_test extends PHPUnit_Framework_TestCase $a = $this->returnDefault(); - $rt = new League\OAuth2\Server\Grant\RefreshToken($a); + $rt = new League\OAuth2\Server\Grant\RefreshToken(); $rt->rotateRefreshTokens(true); $a->addGrantType($rt); @@ -314,7 +314,7 @@ class Refresh_Token_test extends PHPUnit_Framework_TestCase $this->session->shouldReceive('associateScope')->andReturn(null); $a = $this->returnDefault(); - $grant = new League\OAuth2\Server\Grant\RefreshToken($a); + $grant = new League\OAuth2\Server\Grant\RefreshToken(); $grant->setAccessTokenTTL(30); $a->addGrantType($grant); @@ -358,7 +358,7 @@ class Refresh_Token_test extends PHPUnit_Framework_TestCase $this->scope->shouldReceive('getScope')->andReturn(array('id' => 1, 'scope' => 'foo')); $a = $this->returnDefault(); - $grant = new League\OAuth2\Server\Grant\RefreshToken($a); + $grant = new League\OAuth2\Server\Grant\RefreshToken(); $grant->setAccessTokenTTL(30); $grant->rotateRefreshTokens(true); $a->addGrantType($grant); @@ -409,7 +409,7 @@ class Refresh_Token_test extends PHPUnit_Framework_TestCase $this->scope->shouldReceive('getScope')->andReturn(array('id' => 1, 'scope' => 'foo')); $a = $this->returnDefault(); - $grant = new League\OAuth2\Server\Grant\RefreshToken($a); + $grant = new League\OAuth2\Server\Grant\RefreshToken(); $grant->setAccessTokenTTL(30); $grant->rotateRefreshTokens(true); $a->addGrantType($grant); From 75482c9e20de7d35ca844970348dba29216ff68c Mon Sep 17 00:00:00 2001 From: Alex Bilbie Date: Thu, 5 Dec 2013 20:32:46 +0000 Subject: [PATCH 4/6] Test setIdentifier because @philsturgeon didn't --- tests/authorization/AuthCodeGrantTest.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/authorization/AuthCodeGrantTest.php b/tests/authorization/AuthCodeGrantTest.php index 43465e5b..fadf90f2 100644 --- a/tests/authorization/AuthCodeGrantTest.php +++ b/tests/authorization/AuthCodeGrantTest.php @@ -29,6 +29,13 @@ class Auth_Code_Grant_Test extends PHPUnit_Framework_TestCase $grant = new League\OAuth2\Server\Grant\AuthCode($a); } + public function test_setIdentifier() + { + $grant = new League\OAuth2\Server\Grant\AuthCode(); + $grant->setIdentifier('foobar'); + $this->assertEquals($grant->getIdentifier(), 'foobar'); + } + public function test_setAuthTokenTTL() { $a = $this->returnDefault(); From e55ca5bc05147ae1a39ed5aafa555aec16575a59 Mon Sep 17 00:00:00 2001 From: Alex Bilbie Date: Thu, 5 Dec 2013 20:41:51 +0000 Subject: [PATCH 5/6] Version bump --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index abb3acd8..5bfaa6f5 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,7 @@ { "name": "league/oauth2-server", "description": "A lightweight and powerful OAuth 2.0 authorization and resource server library with support for all the core specification grants. This library will allow you to secure your API with OAuth and allow your applications users to approve apps that want to access their data from your API.", - "version": "3.0.1", + "version": "3.1", "homepage": "https://github.com/php-loep/oauth2-server", "license": "MIT", "require": { From c6ac1de26b5e047996c806db5514e7f40eac9a56 Mon Sep 17 00:00:00 2001 From: Alex Bilbie Date: Thu, 5 Dec 2013 20:42:42 +0000 Subject: [PATCH 6/6] Updated changelog --- CHANGELOG.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f79af615..3117d8e4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,10 +1,14 @@ # Changelog +## 3.1 (released 2013-12-05) + +* No longer necessary to inject the authorisation server into a grant, the server will inject itself +* Added test for 1419ba8cdcf18dd034c8db9f7de86a2594b68605 + ## 3.0.1 (released 2013-12-02) * Forgot to tell TravisCI from testing PHP 5.3 - ## 3.0 (released 2013-12-02) * Fixed spelling of Implicit grant class (Issue #84)