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;