Jump to content

Mediawiki API & phpbb3 Single Sign On


phliptrip

Recommended Posts

The old solution i used to use for this no longer works due to changes in mediawiki requiring a token to be acquired and attached to the session, I've tried updating this to retreive the token, but I'm a sysadmin not a coder by trade and it's largely unfortunately beyond my current ken (I can get the data back, but even when I'm using regex I know is correct (ran it through a regex checker vs the info being returned by curl and it correctly marks and shows the array with correct info) it returns nothing in the actual app.. and if it did I don't know enough about structuring cookies, sessionids, and tokens to probably be able to fix it beyond that.

 

The original code that worked prior to the authentication api changes was:

<?php
if(isset($_POST['logmein'])) {
define('IN_PHPBB', true);
$phpbb_root_path = './forums/';     //Path to forum
$phpEx = substr(strrchr(__FILE__, '.'), 1);
include($phpbb_root_path . 'common.' . $phpEx);

// Start session management
$user->session_begin();
$auth->acl($user->data);
$user->setup();

if($user->data['is_registered'])
{
    echo 'Already logged on';
}
else
{
    $username = request_var('lgname', '', true);
    $password = request_var('lgpassword', '', true);
    $autologin = (!empty($_POST['autologin'])) ? true : false;

// Media Wiki

$ch=curl_init();
$postfield = "lgname=$username&lgpassword=$password";
$url = "http://localhost/wiki/api.php?action=login"; //url to wiki's api

curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, 1); 
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postfield);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

preg_match_all('/^Set-Cookie: (.*?)=(.*?);/m', curl_exec($ch), $m);
curl_close($ch);
$cookiename = $m[1];
$cookievalue = $m[2];
$cookieexpire = time() + 2592000;
$cookiepath = "/";
$cookiesecure = "0";
$cookiehttponly = "1";
$i = '-1';

// If is not needed for production server, can't have cookie's domain equal to localhost in my tests

if ($_SERVER['HTTP_HOST'] == 'localhost') {
foreach ($m[1] as $value) {
$i = $i+1;
setcookie($cookiename[$i], $cookievalue[$i], $cookieexpire, $cookiepath, NULL, $cookiesecure, $cookiehttponly);
}
}
else {
// If for production server remove all in between these comments
$cookiedomain = ".uvnc.com";
foreach ($m[1] as $value) {
$i = $i+1;
setcookie($cookiename[$i], $cookievalue[$i], $cookieexpire, $cookiepath, $cookiedomain, $cookiesecure, $cookiehttponly);
}
}
// phpbb
$result = $auth->login($username, $password, $autologin);
}
}?>


<?php
if(isset($_POST['logmein'])) {
if ($result['status'] == LOGIN_SUCCESS)
    {
echo 'Success';
unset($_POST['logmein']);
    }
    else
    {
echo 'Fail';
    }
}
?>
<form method="POST" action="">
<input type="text" name="lgname" size="40" /><br />
<input type="password" name="lgpassword"  size="40" /><br />
<input type="submit" value="Log In" name="logmein" />
</form>  

 

I attempted to extract the token by looking at the data returned--

 

$curl_data = curl_exec($ch);

print "---- $curl_data ----";
preg_match('/ (?P<token>\[token\] => )(?P<data>\w*) /', $curl_data, $curl_match);
print "++++" . $curl_match['data'] . "++++";

preg_match_all('/^Set-Cookie: (.*?)=(.*?);/m', $curl_data, $m);

 

I've tried changing the format of the returned api from xmlfm, to phpfm, and txt... and no matter what i can't match the token information.  I'm at a loss.  If someone has a better solution for media wiki external login and setting the cookie i'm open ears!  I've already got the user integration mod working between phpbb and media wiki so the un/pw match but i'm trying to avoid making everyone login once to forum and once to wiki... i'd rather just do both on a custom login page to avoid the annoyances.

Link to comment
Share on other sites

  • 2 months later...
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.