Piwik\Tracker\Request::authenticateTrackingApi PHP Method

authenticateTrackingApi() protected method

These two attributes can be only set by the Super User (passing token_auth).
protected authenticateTrackingApi ( $tokenAuth )
    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");
        }
    }