diff --git a/src/OAuth2/Storage/Pdo.php b/src/OAuth2/Storage/Pdo.php index f8948835b..8aad00e78 100644 --- a/src/OAuth2/Storage/Pdo.php +++ b/src/OAuth2/Storage/Pdo.php @@ -363,18 +363,31 @@ public function scopeExists($scope) public function getDefaultScope($client_id = null) { - $stmt = $this->db->prepare(sprintf('SELECT scope FROM %s WHERE is_default=:is_default', $this->config['scope_table'])); - $stmt->execute(array('is_default' => true)); + $getGlobalDefaults = true; + $defaultScopes = array(); + + if (!is_null($client_id)) { + // Get (default) scopes from client table + $clientScope = $this->getClientScope($client_id); + if (!is_null($clientScope)) { + $getGlobalDefaults = false; + $defaultScopes = explode(' ', trim($clientScope)); + } + } - if ($result = $stmt->fetchAll(\PDO::FETCH_ASSOC)) { - $defaultScope = array_map(function ($row) { - return $row['scope']; - }, $result); + if ($getGlobalDefaults) { + // Get default scopes + $stmt = $this->db->prepare(sprintf('SELECT scope FROM %s WHERE is_default=:is_default', $this->config['scope_table'])); + $stmt->execute(array('is_default' => true)); - return implode(' ', $defaultScope); + if ($result = $stmt->fetchAll(\PDO::FETCH_ASSOC)) { + $defaultScopes = array_map(function ($row) { + return $row['scope']; + }, $result); + } } - - return null; + + return ( (!empty($defaultScopes)) ? implode(' ', $defaultScopes) : null ); } /* JWTBearerInterface */