Authentication API: Difference between revisions
David Berry (talk | contribs) |
David Mudrak (talk | contribs) m (Text replacement - "<code>" to "<syntaxhighlight lang="php">") |
||
(19 intermediate revisions by 8 users not shown) | |||
Line 1: | Line 1: | ||
The '''Authentication API''' describes Moodle's interface functions to authentication plugins. | |||
(This page is incomplete , I'll update it after I have phpdoc commented auth/ldap/lib.php) | |||
Most of the functions are from the [[LDAP_authentication|ldap-authentication module]] and are not implemented (yet?) on other modules. Please feel free to extend other modules to support same features or roll your own module. | |||
Most of functions are from ldap-authentication module and are not implemented (yet?) on other modules. Please feel free to extend other modules to support same features or roll your own module. | |||
Some of new function are still tested and are not documented here yet. | Some of new function are still tested and are not documented here yet. | ||
Line 11: | Line 10: | ||
Basic functions to authenticate users with external db | Basic functions to authenticate users with external db | ||
auth_user_login ($username, $password) | ===Mandatory:=== | ||
<syntaxhighlight lang="php">auth_user_login ($username, $password)</syntaxhighlight> | |||
Authenticate username, password with userdatabase. | Authenticate username, password with userdatabase. | ||
Returns: true if the username and password work and false if they don't | ;Returns:true if the username and password work and false if they don't | ||
Optional: | ===Optional:=== | ||
The following functions are optional , but if present they extend module usability with Moodle. | |||
auth_get_userinfo($username) | |||
<syntaxhighlight lang="php">auth_get_userinfo($username)</syntaxhighlight> | |||
Query other userinformation from database. | Query other userinformation from database. | ||
Returns: | ;Returns:User information in array ''(name => value, ...)'' or ''false'' in case of error. Function honors update-flags so if <syntaxhighlight lang="php">$CFG->auth_user_(atribute)_updatelocal</syntaxhighlight> is present, it will return value only if flag is true. | ||
===COURSE CREATING=== | |||
auth_iscreator($username) | <syntaxhighlight lang="php">auth_iscreator($username)</syntaxhighlight> | ||
should user have rights to create courses | should user have rights to create courses | ||
Returns: | ;Returns:<syntaxhighlight lang="php">true</syntaxhighlight> if user has rights to create cources otherwise false | ||
USER CREATION | ===USER CREATION=== | ||
Functions that enable | Functions that enable user creation, activation and deactivation from moodle to external database | ||
<syntaxhighlight lang="php">auth_user_exists ($username)</syntaxhighlight> | |||
Checks if given username exists on external db | |||
auth_user_create ($userobject,$plainpass) | ;Returns:<syntaxhighlight lang="php">true</syntaxhighlight> if given usernname exist or false | ||
<syntaxhighlight lang="php">auth_user_create ($userobject,$plainpass)</syntaxhighlight> | |||
Creates new user to external db. User should be created in inactive stage until confirmed by email. | Creates new user to external db. User should be created in inactive stage until confirmed by email. | ||
Returns: | ;Returns:<syntaxhighlight lang="php">true</syntaxhighlight> on success otherwise <syntaxhighlight lang="php">false</syntaxhighlight> | ||
auth_user_activate ($username) | |||
<syntaxhighlight lang="php">auth_user_activate ($username)</syntaxhighlight> | |||
activate new user after email-address is confirmed | activate new user after email-address is confirmed | ||
Returns: | ;Returns:<syntaxhighlight lang="php">true</syntaxhighlight> on success otherwise <syntaxhighlight lang="php">false</syntaxhighlight> | ||
auth_user_disable ($username) | |||
<syntaxhighlight lang="php">auth_user_disable ($username)</syntaxhighlight> | |||
deactivate user in external db. | deactivate user in external db. | ||
Returns: | ;Returns:<syntaxhighlight lang="php">true</syntaxhighlight> on success otherwise <syntaxhighlight lang="php">false</syntaxhighlight> | ||
USER INFORMATION AND SYNCRONIZATION | === USER INFORMATION AND SYNCRONIZATION === | ||
auth_get_userlist () | <syntaxhighlight lang="php">auth_get_userlist ()</syntaxhighlight> | ||
Get list of usernames in external db. | Get list of usernames in external db. | ||
Returns: All usernames in array or false on error. | ;Returns:All usernames in array or <syntaxhighlight lang="php">false</syntaxhighlight> on error. | ||
auth_get_users($filter='*') | |||
<syntaxhighlight lang="php">auth_get_users($filter='*')</syntaxhighlight> | |||
Get ALL USEROBJECTS FROM EXTERNAL DB. | Get ALL USEROBJECTS FROM EXTERNAL DB. | ||
Returns: Array of all users as objects from external db | ;Returns:Array of all users as objects from external db | ||
== See also == | |||
* [[Authentication plugins]] | |||
* Using Moodle [http://moodle.org/mod/forum/discuss.php?d=102070 Overview of entire authentication code flow] forum discussion | |||
* Using Moodle [http://moodle.org/mod/forum/view.php?id=42 User authentication forum] | |||
* Moodle Docs [[Manage authentication]] | |||
* [[Authentication FAQ]] | |||
[[Category:Authentication]] |
Latest revision as of 13:02, 14 July 2021
The Authentication API describes Moodle's interface functions to authentication plugins. (This page is incomplete , I'll update it after I have phpdoc commented auth/ldap/lib.php)
Most of the functions are from the ldap-authentication module and are not implemented (yet?) on other modules. Please feel free to extend other modules to support same features or roll your own module.
Some of new function are still tested and are not documented here yet.
Authentication functions
Basic functions to authenticate users with external db
Mandatory:
auth_user_login ($username, $password)
Authenticate username, password with userdatabase.
- Returns
- true if the username and password work and false if they don't
Optional:
The following functions are optional , but if present they extend module usability with Moodle.
auth_get_userinfo($username)
Query other userinformation from database.
- Returns
- User information in array (name => value, ...) or false in case of error. Function honors update-flags so if is present, it will return value only if flag is true.
$CFG->auth_user_(atribute)_updatelocal
COURSE CREATING
auth_iscreator($username)
should user have rights to create courses
- Returns
- if user has rights to create cources otherwise false
true
USER CREATION
Functions that enable user creation, activation and deactivation from moodle to external database
auth_user_exists ($username)
Checks if given username exists on external db
- Returns
- if given usernname exist or false
true
auth_user_create ($userobject,$plainpass)
Creates new user to external db. User should be created in inactive stage until confirmed by email.
- Returns
- on success otherwise
true
false
auth_user_activate ($username)
activate new user after email-address is confirmed
- Returns
- on success otherwise
true
false
auth_user_disable ($username)
deactivate user in external db.
- Returns
- on success otherwise
true
false
USER INFORMATION AND SYNCRONIZATION
auth_get_userlist ()
Get list of usernames in external db.
- Returns
- All usernames in array or on error.
false
auth_get_users($filter='*')
Get ALL USEROBJECTS FROM EXTERNAL DB.
- Returns
- Array of all users as objects from external db
See also
- Authentication plugins
- Using Moodle Overview of entire authentication code flow forum discussion
- Using Moodle User authentication forum
- Moodle Docs Manage authentication
- Authentication FAQ