public static function authenticateSuperUserOrAdmin($tokenAuth, $idSite)
{
if (empty($tokenAuth)) {
return false;
}
Piwik::postEvent('Request.initAuthenticationObject');
/** @var \Piwik\Auth $auth */
$auth = StaticContainer::get('Piwik\\Auth');
$auth->setTokenAuth($tokenAuth);
$auth->setLogin(null);
$auth->setPassword(null);
$auth->setPasswordHash(null);
$access = $auth->authenticate();
if (!empty($access) && $access->hasSuperUserAccess()) {
return true;
}
// Now checking the list of admin token_auth cached in the Tracker config file
if (!empty($idSite) && $idSite > 0) {
$website = Cache::getCacheWebsiteAttributes($idSite);
if (array_key_exists('admin_token_auth', $website) && in_array((string) $tokenAuth, $website['admin_token_auth'])) {
return true;
}
}
Common::printDebug("WARNING! token_auth = {$tokenAuth} is not valid, Super User / Admin was NOT authenticated");
return false;
}