[Mediawiki-l] auto-login in single-sign-on environments

Domas Mituzas midom.lists at gmail.com
Wed Dec 21 19:55:24 UTC 2005


Hi,

I had to make mediawiki work in single-sign-on environment, so ended  
up with single hook and a small extension utilizing it, it just takes  
user parameter from environment, that is provided by HTTP server  
authentication. It completely removes mediawiki account/password  
layer, though does not clean accounts once they've been auto-created.  
Anyway, this is just the idea, than can be polished and used in  
intranets, instead of using AuthPlugin's interface. Moreover, it  
removes lots of mediawiki user object caching, so it would have to be  
moved somewhere in here, as well as sanitizing user names, etc.

Cheers,
Domas

<?

global $wgHooks;
$wgHooks['AutoAuthenticate'][] = 'AuthServerMagic';

$wgExtensionFunctions[]="setupAuthServerMagic";

function setupAuthServerMagic() {
         global $wgSpecialPages;
         unset($wgSpecialPages["Userlogin"]);
         unset($wgSpecialPages["Userlogout"]);
}

function AuthServerMagic(&$user) {

         if ($_SERVER["REMOTE_USER"] == "") {
                 return new User();
         }

         $user = User::newFromName( $_SERVER["REMOTE_USER"] );
         if ( $user->getID() == 0 ) {
                 $user->addToDatabase();
                 $user->setToken();
		$user->setEmail($user."@domain.yaddayadda.com");
		$user->saveSettings();
         } else {
                 /* Should cache some day, I guess :) */
                 $user->loadFromDatabase();
         }
         return true;
}

?>

-- 
http://dammit.lt/



More information about the MediaWiki-l mailing list