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 e052ce57e..f444fa50a 100644 --- a/src/League/OAuth2/Server/Grant/GrantTrait.php +++ b/src/League/OAuth2/Server/Grant/GrantTrait.php @@ -22,6 +22,17 @@ public function getIdentifier() 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 @@ public function setAccessTokenTTL($accessTokenTTL) 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 4dec46951..c5d63d2e8 100644 --- a/src/League/OAuth2/Server/Authorization.php +++ b/src/League/OAuth2/Server/Authorization.php @@ -244,6 +244,10 @@ public function addGrantType(GrantTypeInterface $grantType, $identifier = null) 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 79a541af6..bf9689805 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 4d53bf23b..aa072d098 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 e052ce57e..efbcf22f3 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 @@ public function setAccessTokenTTL($accessTokenTTL) 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 ec0b906b4..2301bd4ee 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 a71afed53..a41c05a68 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 a81a62c37..544105868 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 4c4664f34..baea674aa 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 ee6a5af9f..43465e5b0 100644 --- a/tests/authorization/AuthCodeGrantTest.php +++ b/tests/authorization/AuthCodeGrantTest.php @@ -20,10 +20,19 @@ private function returnDefault() 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 @@ public function test_setAuthTokenTTL() 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 @@ public function test_checkAuthoriseParams_noClientId() 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 @@ public function test_checkAuthoriseParams_noRedirectUri() 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 @@ public function test_checkAuthoriseParams_badClient() $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 @@ public function test_checkAuthoriseParams_missingResponseType() )); $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 @@ public function test_checkAuthoriseParams_badResponseType() )); $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 @@ public function test_checkAuthoriseParams_missingScopes() )); $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 @@ public function test_checkAuthoriseParams_defaultScope() )); $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 @@ public function test_checkAuthoriseParams_defaultScopeArray() )); $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 @@ public function test_checkAuthoriseParams_badScopes() $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 @@ public function test_checkAuthoriseParams_badScopes() 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 @@ public function test_checkAuthoriseParams() )); $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 @@ function test_newAuthoriseRequest() $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 f4bd2db4f..e73184be1 100644 --- a/tests/authorization/AuthServerTest.php +++ b/tests/authorization/AuthServerTest.php @@ -69,6 +69,7 @@ public function test_addGrantType() $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 @@ public function test_addGrantType_noIdentifier() $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 @@ public function test_getStorage() 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 @@ public function test_getGrantType_fail() 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 @@ public function test_issueAccessToken_missingGrantType() 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 @@ public function test_issueAccessToken_badGrantType() 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 @@ public function test_issueAccessToken_missingClientId() 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 @@ public function test_issueAccessToken_missingClientSecret() 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 @@ public function test_issueAccessToken_badClient() $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 @@ public function test_issueAccessToken_missingCode() $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 @@ public function test_issueAccessToken_badCode() $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 @@ public function test_issueAccessToken_passedInput() $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 @@ public function test_issueAccessToken() $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 @@ public function test_issueAccessToken_customExpiresIn() $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 @@ public function test_issueAccessToken_HTTP_auth() $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 753c73e5e..bb3126904 100644 --- a/tests/authorization/ClientCredentialsGrantTest.php +++ b/tests/authorization/ClientCredentialsGrantTest.php @@ -27,7 +27,7 @@ private function returnDefault() 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 @@ public function test_issueAccessToken_clientCredentialsGrant_missingClientId() 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 @@ public function test_issueAccessToken_clientCredentialsGrant_badClient() $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 @@ public function test_issueAccessToken_clientCredentialsGrant_missingScopes() $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 @@ public function test_issueAccessToken_clientCredentialsGrant_defaultScope() $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 @@ public function test_issueAccessToken_clientCredentialsGrant_defaultScopeArray() $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 @@ public function test_issueAccessToken_clientCredentialsGrant_badScope() $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 @@ public function test_issueAccessToken_clientCredentialsGrant_goodScope() $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 @@ function test_issueAccessToken_clientCredentialsGrant_passedInput() $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 @@ function test_issueAccessToken_clientCredentialsGrant() $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 @@ function test_issueAccessToken_clientCredentialsGrant_customExpiresIn() $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 @@ function test_issueAccessToken_clientCredentialsGrant_withRefreshToken() $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 a73054f86..71d2cec30 100644 --- a/tests/authorization/PasswordGrantTest.php +++ b/tests/authorization/PasswordGrantTest.php @@ -27,7 +27,7 @@ private function returnDefault() 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 @@ public function test_issueAccessToken_passwordGrant_missingClientId() 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 @@ public function test_issueAccessToken_passwordGrant_badClient() $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 @@ function test_issueAccessToken_passwordGrant_invalidCallback() $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 @@ function test_issueAccessToken_passwordGrant_missingUsername() $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 @@ function test_issueAccessToken_passwordGrant_missingPassword() $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 @@ function test_issueAccessToken_passwordGrant_badCredentials() $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 @@ public function test_issueAccessToken_passwordGrant_badScopes() $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 @@ public function test_issueAccessToken_passwordGrant_missingScopes() $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 @@ public function test_issueAccessToken_passwordGrant_defaultScope() $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 @@ public function test_issueAccessToken_passwordGrant_defaultScopeArray() $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 @@ public function test_issueAccessToken_passwordGrant_goodScope() $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 @@ function test_issueAccessToken_passwordGrant_passedInput() $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 @@ function test_issueAccessToken_passwordGrant() $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 @@ function test_issueAccessToken_passwordGrant_customExpiresIn() $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 @@ function test_issueAccessToken_passwordGrant_withRefreshToken() $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 f4882454e..290169e33 100644 --- a/tests/authorization/RefreshTokenTest.php +++ b/tests/authorization/RefreshTokenTest.php @@ -23,7 +23,7 @@ private function returnDefault() 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 @@ public function test_issueAccessToken_with_refresh_token() $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 @@ public function test_issueAccessToken_with_refresh_token() 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 @@ public function test_issueAccessToken_refreshTokenGrant_missingClientId() 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 @@ public function test_issueAccessToken_refreshTokenGrant_badClient() $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 @@ public function test_issueAccessToken_refreshTokenGrant_missingRefreshToken() $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 @@ public function test_issueAccessToken_refreshTokenGrant_badRefreshToken() $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 @@ public function test_issueAccessToken_refreshTokenGrant_passedInput() $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 @@ public function test_issueAccessToken_refreshTokenGrant() $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 @@ public function test_issueAccessToken_refreshTokenGrant_rotateTokens() $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 @@ public function test_issueAccessToken_refreshTokenGrant_customExpiresIn() $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 @@ public function test_issueAccessToken_refreshTokenGrant_newScopes() $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 @@ public function test_issueAccessToken_refreshTokenGrant_badNewScopes() $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 43465e5b0..fadf90f2c 100644 --- a/tests/authorization/AuthCodeGrantTest.php +++ b/tests/authorization/AuthCodeGrantTest.php @@ -29,6 +29,13 @@ public function test__construct() $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 abb3acd84..5bfaa6f51 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 f79af615b..3117d8e4e 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)