Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change PDO.php #709

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 22 additions & 9 deletions src/OAuth2/Storage/Pdo.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's return $clientScopes here and remove the $getGlobalDefaults variable all together. This will greatly simplify this function.

}
}

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 */
Expand Down