Login or session problems (such as not being able to log in, immediately getting logged out, randomly getting logged out, not being able to edit due to "loss of session data" errors) can be caused by a large variety of things, which makes debugging them hard.
When investigating or reporting errors, here are a few tips.
Special:CentralLogin
andSpecial:CentralAutoLogin
as well). This can be done by using theNetwork tab in theDeveloper Tools of your web browser (more information:Firefox;Internet Explorer,Chrome and Chromium,Safari).Dumping to a HAR file is an easy way to log all required data.When debugging the default MediaWiki login, look for the following things:
<wikiID>Session
cookie? Is the cookie sent back correctly when the login form is submitted? Does the cookie value persist during multi-step login (e.g. 2FA)? Does the session exist in the backend (you can check withObjectCache::getInstance($wgSessionCacheType))->get("MWSession:$sessionCookieValue")
, usingshell.php).meta=tokens
and returned in theaction=login
request. Clients failing to do this is the most common source of login errors. (Note that the best practice for bots and similar clients is to useowner-only consumers and not use login at all.)<wikiID>Session
,<wikiID>UserName
,<wikiID>UserId
,<wikiID>Token
cookies set (the last one only when the "keep logged in" checkbox was used)? Do theuserId
/userName
/userToken
fields match in the data stored in the backend? Does the token match the value ofuser.user_token
in the database?provideSessionInfo()
method of the session provider (usuallyCookieSessionProvider
), andSessionManager::loadSessionInfoFromStore
. For problems with processing the submitted login request, it'sAuthManager::continueAuthentication()
and thegetAuthenticationRequests()
andbeginPrimaryAuthentication()
methods of the primary authentication provider (by defaultLocalPasswordPrimaryAuthenticationProvider
). Note that these are pretty complex codebases and will be hard to understand if you aren't familiar withSessionManager and AuthManager.When debugging CentralAuth (e.g. Wikimedia sites), the things to look for:
centralauth_Session
,centralauth_User
and (with the "keep logged in" option)centralauth_Token
(typically set on the parent domain). These should be enough to recreate the other cookies when those are missing. The session cookie corresponds to the central session; its data can be checked withMediaWiki\MediaWikiServices::getInstance()->get('CentralAuth.CentralAuthSessionManager')->getCentralSessionById($sessionCookieValue)
(usingshell.php). The token corresponds toglobaluser.gu_auth_token
in CentralAuth's shared database.Special:CentralLogin/start
→Special:CentralLogin/complete
→ back to the initial page (orreturnTo
target). The /start step sets up a stub central session, and sets cookies for the central domain; the /complete step finalizes the central session, and sets cookies for the local domain. (See phpdoc inSpecialCentralLogin
for a more detailed description.) Are the cookies emitted as expected? Does the browser actually persist them? Is the data stored in the central session backend correct? If this step doesn't work, edge login / autologin won't work either.centralauth_Token
cookie) is set in a separate step, by a request to Special:CentralAutoLogin/refreshCookies that's triggered from an<img>
tag when the rest of the autologin is finished. Are the cookies emitted? Does the browser actually persist them? When this step doesn't work, edge login / autologin will stop working when the central session expires in a day or so.$wgCentralAuthAutoLoginWikis
, there is a redirect chain to various Special:CentralAutologin subpages (/start → /checkLoggedIn → /createSession → /validateSession → /setCookies) via an image embedded in the page. The setCookies step should create a local session and set the session cookies. Are the cookies emitted? Does the browser actually persist them?CentralAuthAnon
localStorage flag; you might need to clear that when testing.There's anoverview of CentralAuth authentication features available.
$wgSessionCacheType
), and make sure it works (data is actually persisted between requests). The most safe configuration is$wgSessionCacheType=CACHE_DB;
. If you're unsure about how it's configured, add this setting at the end of your LocalSettings.php.$wgCookieDomain
and$wgCookiePath
are correct.$wgCookieSecure
is set to true, your webserver must be served with HTTPS.httpd.conf
. For example, for the domainexample.com
and the web server located atwww.example.com
:# LocalSettings.php$wgServer = '//www.example.com';$wgCanonicalServer = 'https://www.example.com';$wgSitename = 'Example Wiki';$wgSecureLogin = true;$wgCookieHttpOnly = true;$wgCookieSecure = 'detect';
# httpd.conf<VirtualHost *:80> ... ServerName example.com ServerAlias www.example.com *.example.com Redirect permanent / https://example.com/ ...</VirtualHost><VirtualHost *:443> ... SSLEngine on ServerName example.com ServerAlias www.example.com *.example.com ...</VirtualHost>
$wgSessionProviders
).authentication
,session
,cookie
,objectcache
channels (besides the usualexception
,error
,fatal
). Alsocaptcha
if your are looking into CAPTCHA issues, andCentralAuth
if you are using that extension.$wgHooks['SetupAfterCache'][]=function(){global$wgSessionCacheType;ObjectCache::getInstance($wgSessionCacheType)->setDebug(true);};