authhooks.rst 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. ======================
  2. Authentication Hooks
  3. ======================
  4. This documents the hooks that are currently available for authentication
  5. plugins. If you need new hooks for your plugin, go ahead a submit a patch.
  6. What hooks are available?
  7. =========================
  8. 'authentication'
  9. ----------------
  10. This hook just needs to return ``True`` as this is how
  11. the MediaGoblin app knows that an authentication plugin is enabled.
  12. 'auth_extra_validation'
  13. -----------------------
  14. This hook is used to provide any additional validation of the registration
  15. form when using ``mediagoblin.auth.tools.register_user()``. This hook runs
  16. through all enabled auth plugins.
  17. 'auth_create_user'
  18. ------------------
  19. This hook is used by ``mediagoblin.auth.tools.register_user()`` so plugins can
  20. store the necessary information when creating a user. This hook runs through
  21. all enabled auth plugins.
  22. 'auth_get_user'
  23. ---------------
  24. This hook is used by ``mediagoblin.auth.tools.check_login_simple()``. Your
  25. plugin should return a ``User`` object given a username.
  26. 'auth_no_pass_redirect'
  27. -----------------------
  28. This hook is called in ``mediagoblin.auth.views`` in both the ``login`` and
  29. ``register`` views. This hook should return the name of your plugin, so that
  30. if :ref:`basic_auth-chapter` is not enabled, the user will be redirected to the
  31. correct login and registration views for your plugin.
  32. The code assumes that it can generate a valid url given
  33. ``mediagoblin.plugins.{{ your_plugin_here }}.login`` and
  34. ``mediagoblin.plugins.{{ your_plugin_here }}.register``. This is only needed if
  35. you will not be using the ``login`` and ``register`` views in
  36. ``mediagoblin.auth.views``.
  37. 'auth_get_login_form'
  38. ---------------------
  39. This hook is called in ``mediagoblin.auth.views.login()``. If you are not using
  40. that view, then you do not need this hook. This hook should take a ``request``
  41. object and return the ``LoginForm`` for your plugin.
  42. 'auth_get_registration_form'
  43. ----------------------------
  44. This hook is called in ``mediagoblin.auth.views.register()``. If you are not
  45. using that view, then you do not need this hook. This hook should take a
  46. ``request`` object and return the ``RegisterForm`` for your plugin.
  47. 'auth_gen_password_hash'
  48. ------------------------
  49. This hook should accept a ``raw_pass`` and an ``extra_salt`` and return a
  50. hashed password to be stored in ``User.pw_hash``.
  51. 'auth_check_password'
  52. ---------------------
  53. This hook should accept a ``raw_pass``, a ``stored_hash``, and an ``extra_salt``.
  54. Your plugin should then check that the ``raw_pass`` hashes to the same thing as
  55. the ``stored_hash`` and return either ``True`` or ``False``.
  56. 'auth_fake_login_attempt'
  57. -------------------------
  58. This hook is called in ``mediagoblin.auth.tools.check_login_simple``. It is
  59. called if a user is not found and should do something that takes the same amount
  60. of time as your ``check_password`` function. This is to help prevent timining
  61. attacks.