Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.3.x will end 7 October 2024 (12 months).
  • Bug fixes for security issues in 4.3.x will end 21 April 2025 (18 months).
  • PHP version: minimum PHP 8.0.0 Note: minimum PHP version has increased since Moodle 4.1. PHP 8.2.x is supported too.
/auth/mnet/ -> auth.php (source)

Differences Between: [Versions 310 and 403] [Versions 311 and 403] [Versions 39 and 403] [Versions 400 and 403] [Versions 401 and 403]

Authentication Plugin: Moodle Network Authentication Multiple host authentication support for Moodle Network.

Author: Martin Dougiamas
License: http://www.gnu.org/copyleft/gpl.html GNU Public License
File Size: 1207 lines (49 kb)
Included or required:0 times
Referenced: 1 time
Includes or requires: 0 files

Defines 2 classes


Class: auth_plugin_mnet  - X-Ref

Moodle Network authentication plugin.

__construct()   X-Ref
Constructor.


auth_plugin_mnet()   X-Ref
Old syntax of class constructor. Deprecated in PHP7.


Class: name  - X-Ref

user_login($username, $password)   X-Ref
This function is normally used to determine if the username and password
are correct for local logins. Always returns false, as local users do not
need to login over mnet xmlrpc.

param: string $username The username
param: string $password The password
return: bool Authentication success or failure.

user_authorise($token, $useragent)   X-Ref
Return user data for the provided token, compare with user_agent string.

param: string $token    The unique ID provided by remotehost.
param: string $useragent       User Agent string.
return: array  $userdata Array of user info for remote host

generate_token()   X-Ref
Generate a random string for use as an RPC session token.


start_jump_session($mnethostid, $wantsurl, $wantsurlbackhere=false)   X-Ref
Starts an RPC jump session and returns the jump redirect URL.

param: int $mnethostid id of the mnet host to jump to
param: string $wantsurl url to redirect to after the jump (usually on remote system)
param: boolean $wantsurlbackhere defaults to false, means that the remote system should bounce us back here

confirm_mnet_session($token, $remotepeer)   X-Ref
This function confirms the remote (ID provider) host's mnet session
by communicating the token and UA over the XMLRPC transport layer, and
returns the local user record on success.

param: string    $token           The random session token.
param: mnet_peer $remotepeer   The ID provider mnet_peer object.
return: array The local user record.

update_mnet_session($user, $token, $remotepeer)   X-Ref
creates (or updates) the mnet session once
{@see confirm_mnet_session} and {@see complete_user_login} have both been called

param: stdclass  $user the local user (must exist already
param: string    $token the jump/land token
param: mnet_peer $remotepeer the mnet_peer object of this users's idp

update_enrolments($username, $courses)   X-Ref
Invoke this function _on_ the IDP to update it with enrolment info local to
the SP right after calling user_authorise()

Normally called by the SP after calling user_authorise()

param: string $username The username
param: array $courses  Assoc array of courses following the structure of mnetservice_enrol_courses
return: bool

prevent_local_passwords()   X-Ref
No description

is_internal()   X-Ref
Returns true if this authentication plugin is 'internal'.

return: bool

can_change_password()   X-Ref
Returns true if this authentication plugin can change the user's
password.

return: bool

change_password_url()   X-Ref
Returns the URL for changing the user's pw, or false if the default can
be used.

return: moodle_url

keepalive_client()   X-Ref
Poll the IdP server to let it know that a user it has authenticated is still
online

return: void

refresh_log($array)   X-Ref
Receives an array of log entries from an SP and adds them to the mnet_log
table

param: array   $array      An array of usernames
return: string              "All ok" or an error message

keepalive_server($array)   X-Ref
Receives an array of usernames from a remote machine and prods their
sessions to keep them alive

param: array   $array      An array of usernames
return: string              "All ok" or an error message

prelogout_hook()   X-Ref
Cleanup any remote mnet_sessions, kill the local mnet_session data

This is called by require_logout in moodlelib

return: void

kill_parent($username, $useragent)   X-Ref
The SP uses this function to kill the session on the parent IdP

param: string  $username       Username for session to kill
param: string  $useragent      SHA1 hash of user agent to look for
return: string                  A plaintext report of what has happened

kill_children($username, $useragent)   X-Ref
The IdP uses this function to kill child sessions on other hosts

param: string  $username       Username for session to kill
param: string  $useragent      SHA1 hash of user agent to look for
return: string                  A plaintext report of what has happened

kill_child($username, $useragent)   X-Ref
When the IdP requests that child sessions are terminated,
this function will be called on each of the child hosts. The machine that
calls the function (over xmlrpc) provides us with the mnethostid we need.

param: string  $username       Username for session to kill
param: string  $useragent      SHA1 hash of user agent to look for
return: bool                    True on success

end_local_sessions(&$sessionArray)   X-Ref
To delete a host, we must delete all current sessions that users from
that host are currently engaged in.

param: string  $sessionidarray   An array of session hashes
return: bool                      True on success

fetch_user_image($username)   X-Ref
Returns the user's profile image info

If the user exists and has a profile picture, the returned array will contain keys:
f1          - the content of the default 100x100px image
f1_mimetype - the mimetype of the f1 file
f2          - the content of the 35x35px variant of the image
f2_mimetype - the mimetype of the f2 file

The mimetype information was added in Moodle 2.0. In Moodle 1.x, images are always jpegs.

param: int $username The id of the user
return: false|array false if user not found, empty array if no picture exists, array with data otherwise

fetch_theme_info()   X-Ref
Returns the theme information and logo url as strings.

return: string     The theme info

has_service($mnethostid, $servicename)   X-Ref
Determines if an MNET host is providing the nominated service.

param: int    $mnethostid   The id of the remote host
param: string $servicename  The name of the service
return: bool                Whether the service is available on the remote host

can_login_remotely($username, $mnethostid)   X-Ref
Checks the MNET access control table to see if the username/mnethost
is permitted to login to this moodle.

param: string $username   The username
param: int    $mnethostid The id of the remote mnethost
return: bool              Whether the user can login from the remote host

logoutpage_hook()   X-Ref
No description

trim_logline($logline)   X-Ref
Trims a log line from mnet peer to limit each part to a length which can be stored in our DB

param: object $logline The log information to be trimmed
return: object The passed logline object trimmed to not exceed storable limits

loginpage_idp_list($wantsurl)   X-Ref
Returns a list of MNet IdPs that the user can roam from.

param: string $wantsurl The relative url fragment the user wants to get to.
return: array List of arrays with keys url, icon and name.

test_settings()   X-Ref
Test if settings are correct, print info to output.