Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MediaWiki Extension:GoogleAppsAuthentification Multiple Domains

I've been using the great GoogleAppsAuthentification extension for mediawiki to allow my users to log in with their Google Apps account. We recently added another domain to our Google Apps and I'd like to offer those users the option to log into our wiki with their Google Apps Domain.

Out of the box, this isn't possible with the extension, however it seems pretty trivial to add multiple domain support.

The idea is to prompt the user with a dropdown list of available domains prior to executing the redirect to Google's login screen.

My knowledge of the mediawiki API is rather limited and I could use some pointers.

the extension hooks into the UserLoadFromSession hook, which is called before the UserLoginForm hook. I would have to add code to this function to prompt the user for a domain, and return to this function, passing the selected domain to getGoogleAccount()

// in LocalSettings.py
$wgDefaultUserOptions['GoogleAppsDomainList'] = array("domain.com", "otherdomain.com");

// in GoogleAppsAuthentication.php
function fnGoogleAppsAuthenticateHook($user, &$result){
    global $IP, $wgLanguageCode, $wgRequest, $wgOut, $wgDefaultUserOptions;
    if (isset($_REQUEST["title"])){
            $lg = Language::factory($wgLanguageCode);

            if ($_REQUEST["title"] == $lg->specialPage("Userlogin")){
                    // this is where we need to add the prompt 
                    // that asks the user which domain to chose
                    $domain = getDomainFromUser($wgDefaultUserOptions['GoogleAppsDomainList'])

                    // Setup for a web request
                    require_once("$IP/includes/WebStart.php");

                    // Here we do our stuff
                    $googleAccount = getGoogleAccount('title=' . $_REQUEST["title"], $domain);

                    // whole bunch of code here that won't be affected by our change
                    ...
                    // end whole bunch of code that won't be affected by our change
            } else if ($_REQUEST["title"] == $lg->specialPage("Userlogout")) {
                    session_unset();
                    // Logout
                    $user->logout();
            }
    }

    // Back to MediaWiki home after login
    return true;
}


function getDomainFromUser($domainList) {
    // render page with dropdown containing domains in $domainList
    // get selected dropdown on page submit
    // return selected domain
}

I need some help with the getDomainFromUser() function. I don't know how to redirect to a new page that shows a dropdown menu populated by an array defined in the LocalSettings.py and return the selected value back to the fnGoogleAppsAuthenticateHook function.

Any help would be sincerely appreciated. I believe a lot more people can benefit from this additional functionality added to this extension.

like image 312
Jule Slootbeek Avatar asked Jan 14 '14 18:01

Jule Slootbeek


1 Answers

Unless i have misunderstood your need:

If you have enabled $_SESSION:

in "// in LocalSettings.py"

Line 1 of code: start session engine

<?php session_start(); ?>

Code at point of array definition: take the array and copy it to session variable so it can be accessed by other pages, functions etc.

<?php
$wgDefaultUserOptions['GoogleAppsDomainList'] = array("domain.com", "otherdomain.com");
$_SESSION['a']=$wgDefaultUserOptions['GoogleAppsDomainList'];
?>

On page where you want dropdown selection to occur:

Line 1 of code: Start session engine

<?php session_start(); ?>

@point where you need drop-down selection

<Form action="**processing page**" method="post">
<select name="Domain-Choice" >
 <?php
 foreach ($_SESSION['a'] as $key)
 {echo "<option value=\"".$key."\">".$key."</option>";}
 ?> 
 </select>
 </Form>

Set your form action to whatever PHP processing page you want, $_POST['Domain-Choice'] will have value selected by user from drop-down which was populated from the array stored in session variable, copied from array set in LocalSettings.py ($wgDefaultUserOptions['GoogleAppsDomainList'])

If I misunderstood what you need, sorry in advance.

like image 88
DMSJax Avatar answered Sep 29 '22 11:09

DMSJax