|
| 1 | +<p align="center"> |
| 2 | + <picture> |
| 3 | + <source media="(prefers-color-scheme: dark)" srcset="https://github.com/codingjoe/django-mail-auth/raw/main/images/logo-dark.svg"> |
| 4 | + <source media="(prefers-color-scheme: light)" srcset="https://github.com/codingjoe/django-mail-auth/raw/main/images/logo-light.svg"> |
| 5 | + <img alt="Django MailAuth: Secure login links; no passwords required!" src="https://github.com/codingjoe/django-mail-auth/raw/main/images/logo-light.svg"> |
| 6 | + </picture> |
| 7 | +</p> |
| 8 | + |
| 9 | +# Django Mail Auth |
| 10 | + |
| 11 | +[](https://pypi.python.org/pypi/django-mail-auth/) |
| 12 | +[](https://django-mail-auth.readthedocs.io/en/latest/?badge=latest) |
| 13 | +[](https://codecov.io/gh/codingjoe/django-mail-auth) |
| 14 | +[](https://raw.githubusercontent.com/codingjoe/django-mail-auth/main/LICENSE) |
| 15 | + |
| 16 | +Django Mail Auth is a lightweight authentication backend for Django, |
| 17 | +that does not require users to remember passwords. |
| 18 | + |
| 19 | +Django Mail Auth features: |
| 20 | + |
| 21 | +- custom user model support |
| 22 | +- drop in Django admin support |
| 23 | +- drop in Django User replacement |
| 24 | +- drop in Wagtail login replacement |
| 25 | +- extendable SMS support |
| 26 | + |
| 27 | +{alt="screenshot from a login form" width="425px"} |
| 28 | + |
| 29 | +This project was inspired by: |
| 30 | + |
| 31 | +- [Is it time for password-less login?](http://notes.xoxco.com/post/27999787765/is-it-time-for-password-less-login) |
| 32 | + by [Ben Brown](http://twitter.com/benbrown) |
| 33 | +- [LOGIN WITHOUT PASSWORD MOST SECURE | WAIT.. WHAT?](https://www.lucius.digital/en/blog/login-without-password-most-secure-wait-what) |
| 34 | + by [Joris Snoek](https://twitter.com/lucius_digital) |
| 35 | +- [django-nopassword](https://github.com/relekang/django-nopassword) by |
| 36 | + [Rolf Erik Lekang](http://rolflekang.com) |
| 37 | + |
| 38 | +## Installation |
| 39 | + |
| 40 | +Run this command to install `django-mail-auth`: |
| 41 | + |
| 42 | +``` |
| 43 | +python3 -m pip install django-mail-auth[wagtail] |
| 44 | +``` |
| 45 | + |
| 46 | +## Setup |
| 47 | + |
| 48 | +First add `mailauth` to you installed apps: |
| 49 | + |
| 50 | +```python |
| 51 | +INSTALLED_APPS = [ |
| 52 | + # Django's builtin apps… |
| 53 | + "mailauth", |
| 54 | + "mailauth.contrib.admin", # optional |
| 55 | + "mailauth.contrib.user", # optional |
| 56 | + # optional, must be included before "wagtail.admin" |
| 57 | + "mailauth.contrib.wagtail", |
| 58 | + # other apps… |
| 59 | +] |
| 60 | +``` |
| 61 | + |
| 62 | +`mailauth.contrib.admin` is optional and will replace the admin's login |
| 63 | +with token based authentication too. |
| 64 | + |
| 65 | +`mailauth.contrib.user` is optional and provides a new Django User |
| 66 | +model. The new User model needs to be enabled via the `AUTH_USER_MODEL` |
| 67 | +setting: |
| 68 | + |
| 69 | +```python |
| 70 | +# This setting should be either "EmailUser" or |
| 71 | +# any custom subclass of "AbstractEmailUser" |
| 72 | +AUTH_USER_MODEL = "mailauth_user.EmailUser" |
| 73 | + |
| 74 | +# optional, Wagtail only |
| 75 | +WAGTAILUSERS_PASSWORD_ENABLED = False |
| 76 | +``` |
| 77 | + |
| 78 | +Next you will need to add the new authentication backend: |
| 79 | + |
| 80 | +```python |
| 81 | +AUTHENTICATION_BACKENDS = ( |
| 82 | + # default, but now optional |
| 83 | + # This should be removed if you use mailauth.contrib.user or any other |
| 84 | + # custom user model that does not have a username/password |
| 85 | + "django.contrib.auth.backends.ModelBackend", |
| 86 | + # The new access token based authentication backend |
| 87 | + "mailauth.backends.MailAuthBackend", |
| 88 | +) |
| 89 | +``` |
| 90 | + |
| 91 | +Django's `ModelBackend` is only needed, if you still want to support |
| 92 | +password based authentication. If you don't, simply remove it from the |
| 93 | +list. |
| 94 | + |
| 95 | +Last but not least, go to your URL root configuration `urls.py` and add |
| 96 | +the following: |
| 97 | + |
| 98 | +```python |
| 99 | +from django.urls import path |
| 100 | + |
| 101 | + |
| 102 | +urlpatterns = [ |
| 103 | + path("accounts/", include("mailauth.urls")), |
| 104 | + # optional, must be before "wagtail.admin.urls" |
| 105 | + path("", include("mailauth.contrib.wagtail.urls")), |
| 106 | +] |
| 107 | +``` |
| 108 | + |
| 109 | +That's it! |
| 110 | + |
| 111 | +> [!IMPORTANT] |
| 112 | +> Don't forget to setup you Email backend! |
0 commit comments