The module is working great for logins across all sites (great work!), however cron.php never gets run on any of the slave sites. Running `wget http://mysite/cron.php` manually shows that it is choking on the authentication redirects. I don't know if this is the right answer, but I was able to work around the problem by adding these lines to the beginning of singlesignon_init():

  // If in cron script, do nothing
  if ($_SERVER['REQUEST_URI'] == '/cron.php') {
    return null;
  }

Comments

localhost@2006.planet-soc.com’s picture

Status: Active » Needs work

Hello, I found the same problem when I attempted to make a cron script that I could run with the Windows scheduler. First I'll explain my setup as this might play a part in the validity of my code below. I'm using the Ionic Isapi URL Rewrite Filter (IIRF) with PHP 5.2.2 on IIS 6 on a Windows server. So I can verify that this code works correctly on Windows.

My attempt is more a less a hack to cron.php and the singlesignon.module files. While this might not be the best implementation, I believe something like this should be considered, as chances are, other forms of issues could occur for scripts other than just cron.php and this one way to plan for future uses.

Note: the $_singlesignon_noredirect_ variable might be done best as an array (a better variable name should probably be used).

Below are the code chunks with the changes made being indicated by comments:

cron.php

include_once './includes/bootstrap.inc';

// START CHANGE
// This setting indicates to the singlesignon module to not perform redirection
$_singlesignon_noredirect_ = 1;
// END CHANGE

drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
drupal_cron_run();

singlesignon.module

function singlesignon_init() {

  // START CHANGE
  // change: Added $_singlesignon_noredirect_ to the globals list
  global $base_url, $user, $_singlesignon_noredirect_;
  // END CHANGE
...
      // url() only available if bootstrap has reached FULL.
      drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);

      // START CHANGE
      // SingleSignOn has issues with the redirect if it occurs for the cron script (possibly others?)
      // added the two if conditionals and indented the singlesignon and else that returns
      if(!isset($_singlesignon_noredirect_)	&&
      	($_singlesignon_noredirect_ != 1)) {
	      /*
	       * This is the user's first hit to a slave site.  Take note of their
	       * session ID, since that's how we tell if they've been here or not.
	       * Then go to the master site to see if they are logged in over there.
	       */
	      $_SESSION['singlesignon_prior_sid'] = session_id();
	      $query = 'slave_session=' . session_id()
	             . '&singlesignon_dest=' . singlesignon_get_dest();
	      singlesignon_goto($master_url . url('singlesignon/initial_check', $query));
      } else {
              return;
      }
      // END CHANGE
    }
starkos’s picture

I have a fix for this and several related problems; you can get it from my site (along with a brief explanation of the fix).

wayland76’s picture

Status: Needs work » Closed (duplicate)