We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 7966
    • 90 Posts
    I had the following JS code which was working before, to call the component connector.

    receiveReq.open("GET", '/assets/components/mytools/connector.php?action=getcontent&c='+ca+'&pid='+pid, true);
    receiveReq.onreadystatechange = handlegetContent;
    receiveReq.send(null);
    


    But after the update, I got the following error.

    {"success":false,"message":"Access denied.","total":0,"data":[],"object":[]}


    Is the following statement from ". It can either be passed in the HTTP headers as 'modAuth', or in a REQUEST var as HTTP_MODAUTH" from http://rtfm.modx.com/display/revolution20/Developing+an+Extra+in+MODX+Revolution%2C+Part+II still valid with modx 2.2.

    I added the modAuth to headers as follow, but that didn't help

    receiveReq.open("GET", '/assets/components/mytools/connector.php?action=getcontent&c='+ca+'&pid='+pid, true);
    receiveReq.setRequestHeader('modAuth', 'modx111111122222);
    receiveReq.onreadystatechange = handlegetContent;
    receiveReq.send(null);
    


    Anyone have any idea what could be wrong.

    Thank you



      • 28215
      • 4,149 Posts
      I don't believe any changes were made. What happens if you pass the request var with the key HTTP_MODAUTH?
        shaun mccormick | bigcommerce mgr of software engineering, former modx co-architect | github | splittingred.com
        • 7966
        • 90 Posts
        I had the following code in connector.php

        $basePath =   dirname( dirname( dirname( dirname( __FILE__ ) ) )) ;
        
        require_once $basePath . '/config.core.php';
        require_once MODX_CORE_PATH . 'config/' . MODX_CONFIG_KEY . '.inc.php';
        require_once MODX_CONNECTORS_PATH . 'index.php';
        $_SERVER['HTTP_MODAUTH'] = $modx->site_id;
        
        //echo $modx->getOption( 'core_path' ) . 'components/mytools/processors/';
        $path = $modx->getOption( 'core_path' ) . 'components/mytools/processors/';
        
        $modx->request->handleRequest(array(
            'processors_path' => $path,
            'location' => '',
        ));
        


        It was working fine before but now got the error message.

        I don't know if it is related in any way but I have seen the following bug as resolved; http://tracker.modx.com/issues/5044.

        Thank you
          • 7966
          • 90 Posts
          I changed the connector.php as follow, and I don't know why but now it works.

          $basePath =   dirname( dirname( dirname( dirname( __FILE__ ) ) )) ;
          
          require_once $basePath . '/config.core.php';
          require_once MODX_CORE_PATH . 'config/' . MODX_CONFIG_KEY . '.inc.php';
          require_once MODX_CONNECTORS_PATH . 'index.php';
          //$_SERVER['HTTP_MODAUTH'] = $modx->site_id;
          
          if ($_REQUEST['action'] == 'getcontent') {
              $version = $modx->getVersionData();
              if (version_compare($version['full_version'],'2.1.1-pl') >= 0) {
                  if ($modx->user->hasSessionContext($modx->context->get('key'))) {
                      $_SERVER['HTTP_MODAUTH'] = $_SESSION["modx.{$modx->context->get('key')}.user.token"];
                  } else {
                      $_SESSION["modx.{$modx->context->get('key')}.user.token"] = 0;
                      $_SERVER['HTTP_MODAUTH'] = 0;
                  }
              } else {
                  $_SERVER['HTTP_MODAUTH'] = $modx->site_id;
              }
              $_REQUEST['HTTP_MODAUTH'] = $_SERVER['HTTP_MODAUTH'];
          }
          
          /* handle request */
          $path = $modx->getOption( 'core_path' ) . 'components/mytools/processors/';
            $modx->request->handleRequest(array(
              'processors_path' => $path,
              'location' => '',
          ));