Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.0.x will end 8 May 2023 (12 months).
  • Bug fixes for security issues in 4.0.x will end 13 November 2023 (18 months).
  • PHP version: minimum PHP 7.3.0 Note: the minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is also supported.
/auth/mnet/ -> auth.php (source)

Differences Between: [Versions 310 and 400] [Versions 311 and 400] [Versions 39 and 400] [Versions 400 and 401] [Versions 400 and 402] [Versions 400 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: 1202 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.

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

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

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

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.

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

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()

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

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

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

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

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

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

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

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

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

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.

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

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.

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

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.

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

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.

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

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.

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

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

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

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

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

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