Manual:Hooks/UserLoadFromSession

From MediaWiki.org
Jump to navigation Jump to search
UserLoadFromSession
Available from version 1.13.0
Called to authenticate users on external/environmental means.
Define function:
public static function onUserLoadFromSession( $user, &$result ) { ... }
Attach hook:

In extension.json:

{
	"Hooks": {
		"UserLoadFromSession": "MyExtensionHooks::onUserLoadFromSession"
	}
}

For MediaWiki ≤1.25:

$wgHooks['UserLoadFromSession'][] = 'MyExtensionHooks::onUserLoadFromSession';
Called from:File(s): User.php

For more information about attaching hooks, see Manual:Hooks.
For examples of extensions using this hook, see Category:UserLoadFromSession extensions.

Details[edit]

  • $user: user object being loaded
  • &$result: set this to a boolean value to abort the normal authentication process

This hook replaces AutoAuthenticate, which has been removed in 1.13.

An extension can use this hook to fill in the data of the User object $user from an external session. This is typically used in Authentication extensions.

When the authentication should continue undisturbed after the hook was executed, do not touch $result. When the normal authentication should not happen (e.g., because $user is completely initialized), set $result to any boolean value.

In any case, return true.

See the talk page for sample code for this hook.

Deprecated[edit]

This hook has been deprecated in MediaWiki 1.27. Extensions should implement their own SessionProvider instead (or, in some cases, use the SessionMetadata and SessionCheckInfo hooks). See SessionManager and AuthManager#As a provider for more details.