Skip to content

Instantly share code, notes, and snippets.

@hexmode
Created December 10, 2015 17:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hexmode/dc1c8aeef06fa68bde41 to your computer and use it in GitHub Desktop.
Save hexmode/dc1c8aeef06fa68bde41 to your computer and use it in GitHub Desktop.
{
"name": "PluggableSSO",
"namemsg": "pluggablesso-extensionname",
"version": "0.1",
"author": [
"[//mwstake.org Mark A. Hershberger]"
],
"url": "https://www.mediawiki.org/wiki/Extension:PluggableSSO",
"descriptionmsg": "pluggablesso-desc",
"type": "variable",
"license-name": "GPL-3.0+",
"MessagesDirs": {
"PluggableSSO": [
"i18n"
]
},
"Hooks": {
"AuthPluginSetup": [
"PluggableSSO\\Hooks::onAuthPluginSetup"
]
},
"AutoloadClasses": {
"PluggableSSO\\Hooks": "PluggableSSO.hooks.php"
},
"config": {
},
"manifest_version": 1
}
<?php
/**
* Copyright (c) 2015 Mark A. Hershberger
*
* This file is part of the PluggableSSO MediaWiki extension
*
* PlugggableSSO is free software: you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* PluggableSSO is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with PluggableSSO. If not, see
* <http://www.gnu.org/licenses/>.
*/
class PluggableSSO extends PluggableAuth {
/**
* @since 1.0
*
* @param &$id
* @param &$username
* @param &$realname
* @param &$email
*/
public function authenticate( &$id, &$username, &$realname, &$email ) {
throw new MWException("blah");
}
/**
* @since 1.0
*
* @param User &$user
*/
public function deauthenticate( User &$user ) {
throw new MWException("oog");
}
}
<?php
/**
* Copyright (c) 2015 Mark A. Hershberger
*
* This file is part of the PluggableSSO MediaWiki extension
*
* PlugggableSSO is free software: you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* PluggableSSO is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with PluggableSSO. If not, see
* <http://www.gnu.org/licenses/>.
*/
namespace PluggableSSO;
class Hooks {
static public function onAuthPluginSetup( $wgAuth ) {
if ( !class_exists( 'PluggableAuth' ) ) {
die( '<b>Error:</b> This extension requires the PluggableAuth ' .
'extension to be loaded first' );
}
if ( array_key_exists( 'PluggableAuth_Class', $GLOBALS ) ) {
die( '<b>Error:</b> A value for $PluggableAuth_Class has ' .
'already been set.' );
}
$GLOBALS['PluggableAuth_Class'] = 'PluggableSSO';
$GLOBALS['PluggableAuth_Timeout'] = 0;
$GLOBALS['PluggableAuth_AutoLogin'] = true;
if ( !isset( $_SERVER['REMOTE_USER'] ) ) {
throw new MWException( __CLASS__ . " requires that the webserver" .
"sets REMOTE_USER." );
}
$username = $_SERVER['REMOTE_USER'];
$domain = null;
if ( isset( $GLOBALS['wgAuthRemoteuserDomain'] ) ) {
$domain = $GLOBALS['wgAuthRemoteuserDomain'];
list( $name, $userDomain ) = explode( '@', $username );
if ( $userDomain !== $domain ) {
throw new \MWException( "User doesn't have right domain" );
}
$username = $name;
}
$id = \User::idFromName( "$username" );
if ( $id === null ) {
wfDebugLog( __CLASS__, "Creating User for $username" );
throw new MWException( "TBD" );
}
$session_variable = wfWikiID() . "_userid";
if (
isset( $_SESSION[$session_variable] ) &&
$id != $_SESSION[$session_variable]
) {
wfDebugLog( __CLASS__, "Username didn't match session" );
throw new MWException( "TBD" );
}
$_SESSION[$session_variable] = $id;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment