protected function authenticateTrackingApi($tokenAuth)
{
$shouldAuthenticate = TrackerConfig::getConfigValue('tracking_requests_require_authentication');
if ($shouldAuthenticate) {
try {
$idSite = $this->getIdSite();
} catch (Exception $e) {
$this->isAuthenticated = false;
return;
}
if (empty($tokenAuth)) {
$tokenAuth = Common::getRequestVar('token_auth', false, 'string', $this->params);
}
$cache = PiwikCache::getTransientCache();
$cacheKey = 'tracker_request_authentication_' . $idSite . '_' . $tokenAuth;
if ($cache->contains($cacheKey)) {
Common::printDebug("token_auth is authenticated in cache!");
$this->isAuthenticated = $cache->fetch($cacheKey);
return;
}
try {
$this->isAuthenticated = self::authenticateSuperUserOrAdmin($tokenAuth, $idSite);
$cache->save($cacheKey, $this->isAuthenticated);
} catch (Exception $e) {
Common::printDebug("could not authenticate, caught exception: " . $e->getMessage());
$this->isAuthenticated = false;
}
if ($this->isAuthenticated) {
Common::printDebug("token_auth is authenticated!");
}
} else {
$this->isAuthenticated = true;
Common::printDebug("token_auth authentication not required");
}
}