From 85312f69950e33e7b579712b9725e332e194d791 Mon Sep 17 00:00:00 2001 From: Alex Bilbie Date: Fri, 22 Mar 2013 12:36:18 +0000 Subject: [PATCH] Updated ClientCredentials to properly include scopes --- src/OAuth2/Grant/ClientCredentials.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/OAuth2/Grant/ClientCredentials.php b/src/OAuth2/Grant/ClientCredentials.php index 9b90f55b..19103e3e 100644 --- a/src/OAuth2/Grant/ClientCredentials.php +++ b/src/OAuth2/Grant/ClientCredentials.php @@ -106,13 +106,19 @@ class ClientCredentials implements GrantTypeInterface { if ($scopes[$i] === '') unset($scopes[$i]); // Remove any junk scopes } + if ($this->authServer->scopeParamRequired() === true && 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()); + } + $authParams['scopes'] = array(); foreach ($scopes as $scope) { $scopeDetails = $this->authServer->getStorage('scope')->getScope($scope); if ($scopeDetails === false) { - throw new Exception\ClientException(sprintf(self::$exceptionMessages['invalid_scope'], $scope), 4); + throw new Exception\ClientException(sprintf($this->authServer->getExceptionMessage('invalid_scope'), $scope), 4); } $authParams['scopes'][] = $scopeDetails;