Thanks. Appreciate the pointers.
I now have much of the SSO functionality working with my SMF forum. Here is what my functions in qa-external-users.php look like.
function qa_get_mysql_user_column_type()
{
return 'MEDIUMINT UNSIGNED';
}
function qa_get_login_links($relative_url_prefix, $redirect_back_to_url)
{
return array(
'login' => '
https://kulsara.com/forum/index.php?action=login',
'register' => '
https://kulsara.com/forum/index.php?action=register',
'logout' => '
https://kulsara.com/forum/index.php?action=logout',
);
}
function qa_get_logged_in_user($qa_db_connection)
{
session_start();
$cookiename = 'SMFCookie10';
if (isset($_COOKIE[$cookiename]) && preg_match('~^a:[34]:\{i:0;(i:\d{1,6}|s:[1-8]:"\d{1,8}");i:1;s:(0|40):"([a-fA-F0-9]{40})?";i:2;[id]:\d{1,14};(i:3;i:\d;)?\}
$~', $_COOKIE[$cookiename]) === 1)
$var = @unserialize($_COOKIE[$cookiename]);
else
$var = @unserialize(stripslashes($_COOKIE[$cookiename]));
$member_id = $var[0];
if (@$_COOKIE[$cookiename]) {
$result=mysql_fetch_assoc(
mysql_query(
"SELECT ID_MEMBER, memberName, emailAddress, ID_GROUP FROM smf_members WHERE ID_MEMBER='$member_id'"
)
);
if (is_array($result))
return array(
'userid' => $result['ID_MEMBER'],
'publicusername' => $result['memberName'],
'email' => $result['emailAddress'],
'level' => $result['ID_GROUP'] ? QA_USER_LEVEL_ADMIN : QA_USER_LEVEL_BASIC
);
}
return null;
}
function qa_get_user_email($qa_db_connection, $userid)
{
$result=mysql_fetch_assoc(
mysql_query(
"SELECT emailAddress FROM smf_members WHERE ID_MEMBER='$userid'"
)
);
if (is_array($result))
return $result['emailAddress'];
return null;
}
function qa_get_userids_from_public($qa_db_connection, $publicusernames)
{
$escapedusernames=array();
foreach ($publicusernames as $publicusername)
$escapedusernames[]=$publicusername;
$results=mysql_query(
'SELECT memberName, ID_MEMBER FROM smf_members WHERE memberName IN ('.implode(',', $escapedusernames).')',
$qa_db_connection
);
$publictouserid=array();
while ($result=mysql_fetch_assoc($results))
$publictouserid[$result['memberName']]=$result['ID_MEMBER'];
return $publictouserid;
}
function qa_get_public_from_userids($qa_db_connection, $userids)
{
$escapeduserids=array();
foreach ($userids as $userid)
$escapeduserids[]="'".mysql_real_escape_string($userid, $qa_db_connection)."'";
$results=mysql_query(
'SELECT memberName, ID_MEMBER FROM smf_members WHERE ID_MEMBER IN ('.implode(',', $escapeduserids).')',
$qa_db_connection
);
$useridtopublic=array();
while ($result=mysql_fetch_assoc($results))
$useridtopublic[$result['ID_MEMBER']]=$result['memberName'];
return $useridtopublic;
}
What works using the above code is the following: Basic SSO works. So if I am logged into my SMF forum, I am showed as logged into QA with the correct username at the top. The "Ask a Question" and "Users" tabs also seem to work fine, e.g. in Users I can see the username of the user that posted a question with some points next to the username.
There are a couple of issues that I am still having trouble with:
(1) When I click the Questions tab, I get a warning stating:
Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in qa/qa-external/qa-external-users.php on line 490
Line 490 is the mysql_fetch_assoc() in the function qa_get_public_from_userids
(2) I am still trying to resolve the logout link in the qa_get_login_links function, since I need to include the session id while logging out, which is how SMF does the logout.
Appreciate any pointers here. Thanks again.