Please upgrade here. These earlier versions are no longer being updated and have security issues.

Using jsConnect to integrate with MediaWiki?

Hi all,

I would like to authenticate users of a MediaWiki wiki using jsConnect and my Vanilla 2 forum user database.

My understanding of what's involved is that I need to write an AuthPlugin for authenticating against Vanilla, and that I would need to use the PHP jsConnect client library to send a jsonp query to the Vanilla instance.

There is an extension (often mentioned here in the forums) for Vanilla 1 integration: http://www.mediawiki.org/wiki/Extension:Vanilla_Authentication - unfortunately much has changed since then, and this is not the best way to securely handle authentication anyway.

Has anyone succeeded in making this work? I would love to share a solution, as if no-one has done it I will have to write it :-)

Thanks!
Dave.

Comments

  • hgtonighthgtonight ∞ · New Moderator

    @dneary

    From my understanding, jsConnect lets you log users into Vanilla using an existing application (in this case MediaWiki). If this is what you want to do check out the readme for php here.

    If you get this working, I would be highly interested in your results. :D

    Search first

    Check out the Documentation! We are always looking for new content and pull requests.

    Click on insightful, awesome, and funny reactions to thank community volunteers for their valuable posts.

  • Thanks @hgtonight! I worked that out on my own after a while.

    I have something mostly working, it's a bit hacky.

    I use hooks, the key ones are "UserLoadFromSession", "PersonalUrls" and "GetPreferences". In the preferences hook, I disable the password updating preference for users. In PersonalUrls, I remove "create account", and make the logout/login targets point to the Vanilla forum logout/login page (hard coded, should really pick this up from the Vanilla forum preferences). For logout, I create a Vanilla session and get the TransientKey from it, and use "Target" to make the return-to URLs work correctly.

    Finally, the main function is Vanilla_loadFromSession. I need to detect whether there is a logged in Vanilla user, and whether there is a logged in MediaWiki user (big gotcha: need to get the MW logged in user without calling loadFromSession, which causes an infinite loop).

    If there is no Vanilla session, but the MediaWiki session cookies are set, I clear them and log out the user.

    If the Vanilla session exists, and I'm logged in to MediaWiki with a different user, log out the old user, log an error, and log in the new user.

    If the session exists and I'm not logged in, log me in.

    If, when logging me in, we discover that the user doesn't yet exist in the wiki database, we need to create the user.

    I didn't try to make moderator/admin settings patch up - I figure that my wiki will have few enough moderators and admins that I can handle that manually for the foreseeable future.

    The Vanilla session code looks like this:

    define('APPLICATION', 'Vanilla');
    define('APPLICATION_VERSION', '2.0.16');
    define('DS', '/');
    define('PATH_ROOT', '/var/www/vanilla');
    ob_start();
    require_once(PATH_ROOT.DS.'bootstrap.php');
    ob_end_clean();
    
    // If there is an active Vanilla session, load it.
    function getVanillaSession ()
    {
        // clear any header output from vanilla
        $Session = Gdn::Session();
        $Authenticator = Gdn::Authenticator();
    
        if ($Session->IsValid()) {
            return $Session;
        } else {
            return null;
        }   
    }
    

    Cheers,
    Dave.

    hgtonightUnderDog
  • In case it's not clear, this only works for a forum & wiki on the same host (so you can require_once bootstrap.php) and on the same domain (so that the wiki can query forum cookies).

  • Curious if there was any further progress with this? I currently authenticate MediaWiki against a phpBB3 database, but may want to authenticate against Vanilla in the near future. It'd be useful to have a solid piece of code to do so.

    UnderDog
  • @cools said:
    Curious if there was any further progress with this? I currently authenticate MediaWiki against a phpBB3 database, but may want to authenticate against Vanilla in the near future. It'd be useful to have a solid piece of code to do so.

    jsConnect is there so you can authenticate with anything. You have to do the development that end or pay someone. People are not just sitting around making random implementations.

    I think you want to authenticate using vanilla, that is like @hgtonight said a reverse situation.

    grep is your friend.

  • Sorry, I should have been more specific - I'm not interested in the jsConnect bit, but the code that @dneary posted :)

  • well that is the way of grabbing the session, with the session you have the $Session->User object.

    grep is your friend.

    UnderDoghgtonight
  • LincLinc Senior Bard Detroit Admin
    edited August 2013

    This is the simplest way to load Vanilla's entire framework within another app: https://github.com/lincolnwebs/Glue/blob/master/wp-content/plugins/glue/vanilla.php

    Dunno if it'll be compatible with MediaWiki, but it works for WordPress. Once you include that, you can use standard Vanilla calls to authenticate:

     $Cookie = new Gdn_CookieIdentity();
     $UserID = $Cookie->GetIdentity();
    

    Beware this is memory intense. Every MediaWiki pageview becomes double load, basically (forum view + wiki view).

    hgtonightShadowdare
Sign In or Register to comment.