django-solomon
A Django app for passwordless authentication using magic links.
Features
- Passwordless authentication using magic links sent via email
- Email-based authentication with a built-in CustomUser model
- Configurable link expiration time
- Blacklist functionality to block specific email addresses
- Support for auto-creating users when they request a magic link
- IP address tracking and validation for enhanced security
- Privacy-focused IP anonymization
- Customizable templates for emails and pages
- Compatible with Django's authentication system
- System checks to ensure proper configuration
Installation
pip install django-solomon
Configuration
- Add
django_solomonto yourINSTALLED_APPSin your Django settings:
INSTALLED_APPS = [
# ...
'django_solomon',
# ...
]
- Configure the user model in your settings:
AUTH_USER_MODEL = 'django_solomon.CustomUser'
This setting is required for django-solomon to work properly, as it needs a user model with a unique email field for email-based authentication. You can also use your own custom user model as long as it has a unique email field.
- Add the authentication backend to your settings:
AUTHENTICATION_BACKENDS = [
'django_solomon.backends.MagicLinkBackend',
'django.contrib.auth.backends.ModelBackend', # Keep the default backend
]
- Include the django-solomon URLs in your project's
urls.py:
from django.urls import include, path
urlpatterns = [
# ...
path('auth/', include('django_solomon.urls')),
# ...
]
- Set the login URL in your settings to use django-solomon's login view:
LOGIN_URL = 'django_solomon:login'
This ensures that when users need to authenticate, they'll be redirected to the magic link login page.
- Configure your email settings to ensure emails can be sent:
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'smtp.example.com'
EMAIL_PORT = 587
EMAIL_USE_TLS = True
EMAIL_HOST_USER = 'your-email@example.com'
EMAIL_HOST_PASSWORD = 'your-password'
DEFAULT_FROM_EMAIL = 'your-email@example.com'
Settings
django-solomon provides several settings that you can customize in your Django settings file:
| Setting | Default | Description |
|---|---|---|
SOLOMON_LINK_EXPIRATION |
300 |
The expiration time for magic links in seconds |
SOLOMON_ONLY_ONE_LINK_ALLOWED |
True |
If enabled, only one active magic link is allowed per user |
SOLOMON_CREATE_USER_IF_NOT_FOUND |
False |
If enabled, creates a new user when a magic link is requested for a non-existent email |
SOLOMON_LOGIN_REDIRECT_URL |
settings.LOGIN_REDIRECT_URL |
The URL to redirect to after successful authentication |
SOLOMON_ALLOW_ADMIN_LOGIN |
True |
If enabled, allows superusers to log in using magic links |
SOLOMON_ALLOW_STAFF_LOGIN |
True |
If enabled, allows staff users to log in using magic links |
SOLOMON_MAIL_TEXT_TEMPLATE |
"django_solomon/email/magic_link.txt" |
The template to use for plain text magic link emails |
SOLOMON_MAIL_MJML_TEMPLATE |
"django_solomon/email/magic_link.mjml" |
The template to use for HTML magic link emails (MJML format) |
SOLOMON_LOGIN_FORM_TEMPLATE |
"django_solomon/base/login_form.html" |
The template to use for the login form page |
SOLOMON_INVALID_MAGIC_LINK_TEMPLATE |
"django_solomon/base/invalid_magic_link.html" |
The template to use for the invalid magic link page |
SOLOMON_MAGIC_LINK_SENT_TEMPLATE |
"django_solomon/base/magic_link_sent.html" |
The template to use for the magic link sent confirmation page |
SOLOMON_ENFORCE_SAME_IP |
False |
If enabled, validates that magic links are used from the same IP they were created from |
SOLOMON_ANONYMIZE_IP |
True |
If enabled, anonymizes IP addresses before storing them (removes last octet for IPv4) |
Usage
Basic Usage
- Direct users to the magic link request page at
/auth/magic-link/ - Users enter their email address
- A magic link is sent to their email
- Users click the link in their email
- They are authenticated and redirected to the success URL
Template Customization
You can override the default templates by creating your own versions in your project:
django_solomon/login_form.html- The form to request a magic linkdjango_solomon/magic_link_sent.html- The confirmation page after a magic link is sentdjango_solomon/invalid_magic_link.html- The error page for invalid magic linksdjango_solomon/email/magic_link.txt- The plain text email template for the magic linkdjango_solomon/email/magic_link.mjml- The HTML email template for the magic link (in MJML format)
Alternatively, you can specify custom templates using the settings variables:
SOLOMON_LOGIN_FORM_TEMPLATE- Custom template for the login formSOLOMON_MAGIC_LINK_SENT_TEMPLATE- Custom template for the confirmation pageSOLOMON_INVALID_MAGIC_LINK_TEMPLATE- Custom template for the error pageSOLOMON_MAIL_TEXT_TEMPLATE- Custom template for the plain text emailSOLOMON_MAIL_MJML_TEMPLATE- Custom template for the HTML email (MJML format)
Programmatic Usage
You can also use django-solomon programmatically in your views:
from django.contrib.auth import authenticate, login
from django_solomon.models import MagicLink
from django_solomon.utilities import get_client_ip
# Create a magic link for a user
magic_link = MagicLink.objects.create_for_user(user)
# Create a magic link with IP address tracking
ip_address = get_client_ip(request)
magic_link = MagicLink.objects.create_for_user(user, ip_address=ip_address)
# Authenticate a user with a token
user = authenticate(request=request, token=token)
if user:
login(request, user)
Documentation
For more detailed information, tutorials, and advanced usage examples, please visit the official documentation.
License
This software is licensed under MIT license.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request on Codeberg.
Metadata
Release files for django-solomon 0.5.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| django_solomon-0.5.0.tar.gz | 55.6 kB | Without provenance | Details for django_solomon-0.5.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| django_solomon-0.5.0-py3-none-any.whl | Python 3 | none | any | Details for django_solomon-0.5.0-py3-none-any.whl |
Total release size: 77.6 kB
Release files / django_solomon-0.5.0.tar.gz
| Download URL | django_solomon-0.5.0.tar.gz |
|---|---|
| Size | 55.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
4f0dff13f5e956879aa3431681248731c853b11aa975ceb91b7a637a1c8f6518
|
|
BLAKE2b-256 checksum How to use checksums |
e6aeb4619668d5dedaddee11a1bb75f5f6ff431157584865ec4aa8b516dba52d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.6.14
|
Release files / django_solomon-0.5.0-py3-none-any.whl
| Download URL | django_solomon-0.5.0-py3-none-any.whl |
|---|---|
| Size | 21.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
e6cba058c74f3981339c5ab0b97a74d50ad3c42ed0cea030a49f4db8f0866204
|
|
BLAKE2b-256 checksum How to use checksums |
0b808e1973944264a5e6661b2f1c7e9b3dc65e08794b6a906adc1f1d0c398013
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.6.14
|
Security for django-solomon 0.5.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.