Profile
Back to NewsBack
GitHub Trending 2 min
Reader Mode
codingjoe/django-mail-auth: Django authentication via login URLs, no passwords required

codingjoe/django-mail-auth: Django authentication via login URLs, no passwords required

8 hours ago

Django MailAuth: Secure login links; no passwords required!

Django Mail Auth

version</a> Documentation Status</a> coverage</a> license</a>

Django Mail Auth is a lightweight authentication backend for Django, that does not require users to remember passwords.

Django Mail Auth features:

  • custom user model support
  • drop in Django admin support
  • drop in Django User replacement
  • drop in Wagtail login replacement
  • extendable SMS support
screenshot from a login form

This project was inspired by:

by Ben Brown by Joris Snoek Rolf Erik Lekang

Sponsors

Sponsors</a>

Installation

Run this command to install django-mail-auth:

python3 -m pip install django-mail-auth[wagtail]

Setup

First add mailauth to you installed apps:

INSTALLED_APPS = [
    # Django's builtin apps…
    "mailauth",
    "mailauth.contrib.admin",  # optional
    "mailauth.contrib.user",  # optional
    # optional, must be included before "wagtail.admin"
    "mailauth.contrib.wagtail",
    # other apps…
]

mailauth.contrib.admin is optional and will replace the admin's login with token based authentication too.

mailauth.contrib.user is optional and provides a new Django User model. The new User model needs to be enabled via the AUTH_USER_MODEL setting:

# This setting should be either "EmailUser" or

any custom subclass of "AbstractEmailUser"

AUTH_USER_MODEL = "mailauth_user.EmailUser"

optional, Wagtail only

WAGTAILUSERS_PASSWORD_ENABLED = False

Next you will need to add the new authentication backend:

AUTHENTICATION_BACKENDS = (
    # default, but now optional
    # This should be removed if you use mailauth.contrib.user or any other
    # custom user model that does not have a username/password
    "django.contrib.auth.backends.ModelBackend",
    # The new access token based authentication backend
    "mailauth.backends.MailAuthBackend",
)

Django's ModelBackend is only needed, if you still want to support password based authentication. If you don't, simply remove it from the list.

Last but not least, go to your URL root configuration urls.py and add the following:

from django.urls import path

urlpatterns = [ path("accounts/", include("mailauth.urls")), # optional, must be before "wagtail.admin.urls" path("", include("mailauth.contrib.wagtail.urls")), ]

That's it!

[!IMPORTANT]
Don't forget to setup you Email backend!
Chat with me