SimpleMachines / smf-mw-auth

SMF MediaWiki Authentication
https://www.simplemachines.org
Other
23 stars 18 forks source link

Login trouble with Mediwiki 1.36.1 #17

Closed ThermoMan closed 2 years ago

ThermoMan commented 2 years ago

Description

SMF 2.0.18 Mediwiki 1.36.1 ForumSsoProvider 2.0.0 (downloaded 2021-08-22) PHP 7.4.15 MySQL 8.0.26-0 Ubuntu 20.04.2 Hosting on Dreamhost I am using a Let's Encrypt certificate and Dreamhost rewrites all http URLs to https for that.

Steps to reproduce

Fresh install of SMF with 3 users created Fresh install of MediaWiki with 1 user created (to verify it worked) Fresh install of ForumSsoProvider

The SSO config is at the bottom of the LocalSettings,php file

$wgSMFPath = '/home/USER/subdomain.domain.com/forum/'; $wgFSPSoftware = 'smf2.0'; wfLoadExtension( 'ForumSsoProvider' );

I log into the forum as a regular user. https://subdomain.domain.com/forum then I click the bookmark for the wiki page https://subdomain.domain.com/wiki (note wiki )

Wiki opens just fine, requires login to continue because of $wgGroupPermissions['*']['read'] = false;

I click the log in link and I get

Not Found The requested URL was not found on this server. Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request. The URL has been mangled to

https://subdomain.domain.com/index.php?action=login;return_hash=HASH_VALUE_HERE;return_to=http%3A%2F%2Fsubdomain.domain.com%2F**wiki**%2Findex.php%3Ftitle%3DMain+Page%26board%3Dredirect It is missing the subdirectory name "wiki" in the first part of that URL. I think the URL should be something like

https://subdomain.domain.com/wiki/index.php?action=login;return_hash=HASH_VALUE_HERE;return_to=http%3A%2F%2Fsubdomain.domain.com%2F**wiki**%2Findex.php%3Ftitle%3DMain+Page%26board%3Dredirect

If I modify the doRedirect to add the directory name it stops the 404 but still doesn't log me in.

public function doRedirect(string $action, bool $do_return = false)
{
    global $wgScriptPath;
    // The wiki URL.
    $page = !empty($_GET['returnto']) ? '?title=' . $_GET['returnto'] . '&' : '?';
    $wiki_url = 'https://' . $_SERVER['SERVER_NAME'] . $wgScriptPath . '/index.php' . $page . 'board=redirect';

    // Send this to the forum handler to give us the proper redirect url.
    $redirect_url = $wgScriptPath . $this->fs->getRedirectURL($action, $wiki_url, $do_return);

    // Redirect and leave this.
    header ('Location: ' . $redirect_url);
    exit;
}

Is it the subdomain doing me in? Is it that the wiki is in a different directory than the forum doing me in?

jdarwood007 commented 2 years ago

https://subdomain.domain.com/forum then I click the bookmark for the wiki page https://subdomain.domain.com/**wiki https://subdomain.domain.com/index.php?action=login;return_hash=HASH_VALUE_HERE;return_to=http%3A%2F%2Fsubdomain.domain.com%2Fwiki**%2Findex.php%3Ftitle%3DMain+Page%26board%3Dredirect

Looks like your $boardurl in SMF may be wrong. Check your Settings.php in SMF.

ThermoMan commented 2 years ago

From the Settings.php

########## Forum Info ##########
$mbname = 'NAME';       # The name of your forum.
$language = 'english';      # The default language file set for the forum.
$boardurl = 'https://subdomain.domain.com/forum';       # URL to your forum's folder. (without the trailing /!)
$webmaster_email = 'admin@domain.com';      # Email address to send emails from. (like noreply@yourdomain.com.)
$cookiename = 'SMFCookie999';       # Name of the cookie to set for authentication.

I think I'm going to archive these files and attempt a re-install.

EDIT: OK, reinstalled (and reinstalled the wiki extension) and still have the same issue. The URL, after clicking "log in" on the wiki is malformed.

Also, I'm not expecting to need to click log in on the wiki, I am already logged in on the forum, so why am I not just let into the wiki?

I have to be missing something obvious here unless wiki 1.36.1 changed something that broke the extension.

ThermoMan commented 2 years ago

In the settings I have enabled "Use subdomain independent cookies" and "Force cookies to be secure" (I have an https only site - the hosting domain redirects http to https automatically)

Additionally, I set up debugging with $wgDebugLogFile = "/some/private/path/mediawiki.log"; and found this

[ForumSessionProvider] Constructor initialized.
[ForumSessionProvider] Loading Forum System Settings.
[ForumSessionProvider] Configuration File missing or not readable. Tried to load at 
[ForumSessionProvider] Forum Software Integraiton invalid.
[ForumSessionProvider] Unable to provide session, database not loaded.

This might be the clue I need - that null path in the config file name.

(typo in "Integraiton" - should read "Integration") ;)

ThermoMan commented 2 years ago

OK, I believe I have found the root problem.

So in the ForumSsoProvider.php file In the loadFSSettings() function

The variable named $wgFSPPath was not set.

So in LocalSettings.php I set it to $wgFSPPath = "../forum";

Should this code be looking at $wgSMFPath instead? That variable already exists and already contains the same value..

jdarwood007 commented 2 years ago

Fixed with #18