authentication.php

  1. drupal
    1. 4.6 developer/hooks/authentication.php
    2. 4.7 developer/hooks/authentication.php
    3. 5 developer/hooks/authentication.php

These hooks are defined by authentication modules, modules that define ways users can log on using accounts from other sites and servers.

A module intending to allow authentication should implement all of these hooks. See the contributed jabber.module for an example.

Authentication hooks are typically called by user.module using module_invoke().

Functions & methods

NameDescription
hook_authVerify authentication of a user.
hook_infoDeclare authentication scheme information.

File

developer/hooks/authentication.php
View source
  1. <?php
  2. /**
  3. * @file
  4. * These hooks are defined by authentication modules, modules that define
  5. * ways users can log on using accounts from other sites and servers.
  6. *
  7. * A module intending to allow authentication should implement all of these
  8. * hooks. See the contributed jabber.module for an example.
  9. *
  10. * Authentication hooks are typically called by user.module using
  11. * module_invoke().
  12. */
  13. /**
  14. * @addtogroup hooks
  15. * @{
  16. */
  17. /**
  18. * Verify authentication of a user.
  19. *
  20. * The _auth hook is the heart of any authentication module. This function
  21. * is called whenever a user is attempting to log in using your
  22. * authentication module. The module uses this information to allow or deny
  23. * access to the site.
  24. *
  25. * @param $username
  26. * The substring before the final '@' character in the username field.
  27. * @param $password
  28. * The whole string submitted by the user in the password field.
  29. * @param $server
  30. * The substring after the final '@' symbol in the username field.
  31. * @return
  32. * For successful authentications, this function returns TRUE. Otherwise,
  33. * it returns FALSE.
  34. */
  35. function hook_auth($username, $password, $server) {
  36. if (variable_get('drupal_authentication_service', 0)) {
  37. if (!$server) {
  38. $server = variable_get('drupal_default_da_server', '');
  39. }
  40. else if (variable_get('drupal_default_da_server_only', 0)) {
  41. if (variable_get('drupal_default_da_server', '') != $server) {
  42. return;
  43. }
  44. }
  45. if (!empty($server)) {
  46. $result = xmlrpc("http://$server/xmlrpc.php", 'drupal.login', $username, $password);
  47. if ($result === FALSE) {
  48. drupal_set_message(t('Error %code: %message', array('%code' => xmlrpc_errno(), '%message' => xmlrpc_error_msg())), 'error');
  49. }
  50. else {
  51. return $result;
  52. }
  53. }
  54. }
  55. }
  56. /**
  57. * Declare authentication scheme information.
  58. *
  59. * This hook is required of authentication modules. It defines basic
  60. * information about the authentication scheme.
  61. *
  62. * @param $field
  63. * The type of information requested. Possible values:
  64. * - "name"
  65. * - "protocol"
  66. * @return
  67. * A string containing the requested piece of information. If $field
  68. * is not provided, an array containing all the fields should be returned.
  69. */
  70. function hook_info($field = 0) {
  71. $info['name'] = 'Drupal';
  72. $info['protocol'] = 'XML-RPC';
  73. if ($field) {
  74. return $info[$field];
  75. }
  76. else {
  77. return $info;
  78. }
  79. }
  80. /**
  81. * @} End of "addtogroup hooks".
  82. */
Login or register to post comments