From ddefb2ee160173af1923660962271dd1f56e3432 Mon Sep 17 00:00:00 2001 From: Alex Bilbie Date: Thu, 9 May 2013 10:02:41 -0700 Subject: [PATCH] Set the scope parameter to not be required by default. Fixes #43 --- src/League/OAuth2/Server/Authorization.php | 6 +++--- src/League/OAuth2/Server/Grant/AuthCode.php | 2 +- tests/authorization/AuthCodeGrantTest.php | 1 + 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/League/OAuth2/Server/Authorization.php b/src/League/OAuth2/Server/Authorization.php index 1bd97a5d..d04dc904 100644 --- a/src/League/OAuth2/Server/Authorization.php +++ b/src/League/OAuth2/Server/Authorization.php @@ -59,10 +59,10 @@ class Authorization * Require the "scope" parameter to be in checkAuthoriseParams() * @var boolean */ - protected $requireScopeParam = true; + protected $requireScopeParam = false; /** - * Default scope to be used if none is provided and requireScopeParam is false + * Default scope to be used if none is provided * @var string */ protected $defaultScope = null; @@ -271,7 +271,7 @@ class Authorization * @param boolean $require * @return void */ - public function requireScopeParam($require = true) + public function requireScopeParam($require = false) { $this->requireScopeParam = $require; } diff --git a/src/League/OAuth2/Server/Grant/AuthCode.php b/src/League/OAuth2/Server/Grant/AuthCode.php index 504a729a..99f90a7f 100644 --- a/src/League/OAuth2/Server/Grant/AuthCode.php +++ b/src/League/OAuth2/Server/Grant/AuthCode.php @@ -152,7 +152,7 @@ class AuthCode implements GrantTypeInterface { if ($scopes[$i] === '') unset($scopes[$i]); // Remove any junk scopes } - if ($this->authServer->scopeParamRequired() === true && count($scopes) === 0) { + if ($this->authServer->scopeParamRequired() === true && $this->authServer->getDefaultScope() === null && count($scopes) === 0) { throw new Exception\ClientException(sprintf($this->authServer->getExceptionMessage('invalid_request'), 'scope'), 0); } elseif (count($scopes) === 0 && $this->authServer->getDefaultScope()) { $scopes = array($this->authServer->getDefaultScope()); diff --git a/tests/authorization/AuthCodeGrantTest.php b/tests/authorization/AuthCodeGrantTest.php index 62861b06..fd6b1927 100644 --- a/tests/authorization/AuthCodeGrantTest.php +++ b/tests/authorization/AuthCodeGrantTest.php @@ -156,6 +156,7 @@ class Auth_Code_Grant_Test extends PHPUnit_Framework_TestCase $g = new League\OAuth2\Server\Grant\AuthCode($a); $a->addGrantType($g); $a->addGrantType(new League\OAuth2\Server\Grant\AuthCode($a)); + $a->requireScopeParam(true); $g->checkAuthoriseParams(array( 'client_id' => 1234,