private function addApproval(ClientData $clientData, $userId, $scope) { $approval = $this->storage->getApprovalByResourceOwnerId($clientData->getId(), $userId); if (false === $approval) { // no approval exists, generate a refresh_token and add it $refreshToken = 'code' === $clientData->getType() ? $this->io->getRandomHex() : null; $this->storage->addApproval($clientData->getId(), $userId, $scope, $refreshToken); } else { // an approval exists, we don't care about the scope, we just // update it if needed keeping the same refresh_token $this->storage->updateApproval($clientData->getId(), $userId, $scope); } }