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. $message = new xmlrpcmsg('drupal.login', array(new xmlrpcval($username,
  37. 'string'), new xmlrpcval($password, 'string')));
  38. $client = new xmlrpc_client('/xmlrpc.php', $server, 80);
  39. $result = $client->send($message, 5);
  40. if ($result && !$result->faultCode()) {
  41. $value = $result->value();
  42. $login = $value->scalarval();
  43. }
  44. return $login;
  45. }
  46. /**
  47. * Declare authentication scheme information.
  48. *
  49. * This hook is required of authentication modules. It defines basic
  50. * information about the authentication scheme.
  51. *
  52. * @param $field
  53. * The type of information requested. Possible values:
  54. * - "name"
  55. * - "protocol"
  56. * @return
  57. * A string containing the requested piece of information. If $field
  58. * is not provided, an array containing all the fields should be returned.
  59. */
  60. function hook_info($field = 0) {
  61. $info['name'] = 'Drupal';
  62. $info['protocol'] = 'XML-RPC';
  63. if ($field) {
  64. return $info[$field];
  65. }
  66. else {
  67. return $info;
  68. }
  69. }
  70. /**
  71. * @} End of "addtogroup hooks".
  72. */
Login or register to post comments