/** * @param \League\OAuth2\Server\Entities\ScopeEntityInterface[] $scopes * @param string $grantType * @param ClientEntityInterface $clientEntity * @param null $userIdentifier|string * @return \League\OAuth2\Server\Entities\ScopeEntityInterface[] */ public function finalizeScopes(array $scopes, $grantType, ClientEntityInterface $clientEntity, $userIdentifier = null) { $scopesId = []; foreach ($scopes as $item) { $scopesId[] = $item->getIdentifier(); } $query = ScopesModel::findByScopeId($scopesId); ScopesModel::findByGrantId($grantType, $query); ScopesModel::findByClientId($clientEntity->getIdentifier(), $query); if ($userIdentifier) { ScopesModel::findByUserId($userIdentifier, $query); } $result = $query->all(); $entitys = []; foreach ($result as $item) { foreach ($scopes as $key => $scope) { if ($item->id == $scope->getIdentifier()) { $entitys[$key] = $scope; } } } return $entitys; }