Jul*_*eek 16 php openid mediawiki oauth google-apps
我一直在使用适用于mediawiki 的优秀GoogleAppsAuthentification扩展程序,以允许我的用户使用他们的Google Apps帐户登录.我们最近在我们的Google Apps中添加了另一个域名,我想为这些用户提供使用Google Apps域名登录我们的wiki的选项.
开箱即用,扩展无法实现这一点,但添加多个域支持似乎非常简单.
我们的想法是在执行重定向到Google登录屏幕之前,向用户提示可用域的下拉列表.
我对mediawiki API的了解相当有限,我可以使用一些指针.
扩展挂钩到UserLoadFromSession挂钩,该挂钩在UserLoginForm挂钩之前调用.我必须向此函数添加代码以提示用户输入域,并返回此功能,将所选域传递给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
}
Run Code Online (Sandbox Code Playgroud)
我需要一些getDomainFromUser()函数的帮助.我不知道如何重定向到一个新页面,该页面显示由LocalSettings.py中定义的数组填充的下拉菜单,并将所选值返回给fnGoogleAppsAuthenticateHook函数.
任何帮助将是真诚的感谢.我相信更多人可以从此扩展中添加的这些附加功能中受益.
除非我误解了你的需求:
如果您启用了$_SESSION:
在“//在LocalSettings.py”中
代码第1行:启动会话引擎
<?php session_start(); ?>
Run Code Online (Sandbox Code Playgroud)
数组定义点的代码:获取数组并将其复制到会话变量,以便其他页面、函数等可以访问它。
<?php
$wgDefaultUserOptions['GoogleAppsDomainList'] = array("domain.com", "otherdomain.com");
$_SESSION['a']=$wgDefaultUserOptions['GoogleAppsDomainList'];
?>
Run Code Online (Sandbox Code Playgroud)
在您想要进行下拉选择的页面上:
代码第 1 行:启动会话引擎
<?php session_start(); ?>
Run Code Online (Sandbox Code Playgroud)
@需要下拉选择的点
<Form action="**processing page**" method="post">
<select name="Domain-Choice" >
<?php
foreach ($_SESSION['a'] as $key)
{echo "<option value=\"".$key."\">".$key."</option>";}
?>
</select>
</Form>
Run Code Online (Sandbox Code Playgroud)
将表单操作设置为您想要的任何 PHP 处理页面, $_POST['Domain-Choice'] 将具有用户从下拉列表中选择的值,该值是从存储在会话变量中的数组填充的,从 LocalSettings.py 中设置的数组复制($wgDefaultUserOptions['GoogleAppsDomainList'])
如果我误解了您的需求,请提前抱歉。