Hello,
There might be a good chance that we are few code line from a good single-sign on solution between TYPO3 CMF/S and Moodle:
This SSO system consists of 3 parts where the last part regards the Moodle enrolment procedure. http://www.single-signon.com/ , so a TPA (adapter for Third Party Application) need to be coded regarding to Moodle.
I hope that some of you who are really in to the hart of the Moodle enrolment code could advice about how to change the code from the TPA example below from the phpBB TPA to a coming Moodle TPA. I will test your advice and share the results with you. The code is:
<?
/*
* Signature-Based Single Sign-On Framework
* TPA Adapter for
* phpBB (http://www.phpBB.com )
*
* Version : 0.1
* Last update : 19.05.2004
*
* (c) net&works GmbH, Hannover, Germany
* http://www.single-signon.com
*/
/**
* function which is called after including this file in the SSO-Agent.
*
* @param
* User_Name string Username the Session will be created for
* remote_addr string Remoteaddress of the users system
* agent string Browser
* sso_url string Url where the user will be redirected after establishing a session for him
*
* @return string return the session data
*
* Leave stubs if you dont need all four params.
*/
function sso($User_Name,$ip,$agent,$sso_url) {
global $db, $board_config;
global $phpbb_root_path,$phpEx,$client_ip;
global $exec;
global $HTTP_SERVER_VARS;
define('IN_PHPBB', true);
// load some phpBB-libs etc.
$phpbb_root_path = dirname($exec)."/";
include($phpbb_root_path . "extension.inc");
include($phpbb_root_path . "common.".$phpEx);
// reformat $User_Name
// taken from phpBB's login.php
// not sure what this is for of if it's really neccessary
$username = $User_Name;
$username = substr(str_replace("\'", "'", $username), 0, 25);
$username = str_replace("'", "\'", $username);
// check if the given $User_Name is valid
$sql = "SELECT user_id, username, user_password, user_active, user_level
FROM " . USERS_TABLE . "
WHERE username = '" . str_replace("\'", "''", $username) . "'";
$result = $db->sql_query($sql);
$row = $db->sql_fetchrow($result);
if( !$row || !$row['user_active']) {
//no valid user found; return error
$error = array("Error" => "No account for this user");
return $error;
}
else {
//create the session
$user_ip=encode_ip($client_ip);
$session_id = session_begin($row['user_id'], $user_ip, PAGE_INDEX, FALSE, $autologin);
// prepare sessiondata return-values
// Sessiondata is stored in this Format :
// Array(
// [redirecturl] => $redirecturl
// [0] => Array(
// "CookieName" => $cookiename
// "CookieValue" => $cookievalue
// "CookieExpires" => $expires
// )
// [1] => Array(
// "Cookiename" => $cookiename
// ... and so on
// )
// [1] if you need to pass more than one cookie
//
$return_val[0] = array();
$return_val += array( "redirecturl" => $sso_url."?sid=".$session_id['session_id']);
// pass session data to the SSO-Agent
return $return_val;
}
}
?>