Advanced authentication with OTP and phone number verification
Project description
Moses
Moses is the Django app that provides OTP authentication and phone number email verification by 6-digit verification codes.
Quick start
- Add "moses" to your INSTALLED_APPS setting like this::
INSTALLED_APPS = [
...
'moses',
'django.contrib.admin',
...
'social_django',
]
- Set moses's CustomUser model as AUTH_USER_MODEL::
AUTH_USER_MODEL = 'moses.CustomUser'
- Allow OTP header in django-cors-headers config::
CORS_ALLOW_HEADERS = (
*default_headers,
"otp",
)
- Add MFAModelBackend as Authentication backend to process OTP on authentication::
AUTHENTICATION_BACKENDS = [
'social_core.backends.google.GoogleOAuth2',
'moses.authentication.MFAModelBackend',
...
]
- Add JWTAuthentication to REST_FRAMEWORK's DEFAULT_AUTHENTICATION_CLASSES::
REST_FRAMEWORK = {
...
'DEFAULT_AUTHENTICATION_CLASSES': [
'moses.authentication.JWTAuthentication',
]
}
- Specify Moses's serializers for Djoser::
MOSES = {
"DEFAULT_LANGUAGE": 'en',
"SEND_SMS_HANDLER": "project.common.sms.send",
"SENDER_EMAIL": "noreply@example.com",
"PHONE_NUMBER_VALIDATOR": "project.common.sms.validate_phone_number",
"DOMAIN": DOMAIN,
"URL_PREFIX": "http://localhost:8000", # without trailing slash
"IP_HEADER": "HTTP_CF_CONNECTING_IP" if DEBUG else None,
"LANGUAGE_CHOICES": (
('en', _("English")),
),
}
- Add to your root urls.py::
from moses.admin import OTPAdminAuthenticationForm
from moses import urls as moses_urls
admin.site.site_header = _('Admin Panel')
admin.site.index_title = 'Welcome'
admin.site.login_form = OTPAdminAuthenticationForm
urlpatterns = [
...
path('moses/', include(moses_urls, namespace='moses')),
]
-
Run
python manage.py migrateto create the accounts models. -
Add middleware:
MIDDLEWARE = [
...
'social_django.middleware.SocialAuthExceptionMiddleware',
]
- Add context processors:
TEMPLATES[0]['OPTIONS']['context_processors'] += [
'social_django.context_processors.backends',
'social_django.context_processors.login_redirect',
]
Signals
Moses emits Django signals during credential confirmation workflows. You can listen to these signals in your application to perform custom actions.
Available Signals
phone_number_confirmed
Emitted when a user successfully confirms their phone number.
Parameters:
sender: The User model classuser: The user instance whose phone was confirmedphone_number: The confirmed phone number (str)is_initial_confirmation: True if this is the first confirmation, False if updating phone number
Example usage:
from django.dispatch import receiver
from moses.signals import phone_number_confirmed
from moses.models import CustomUser
@receiver(phone_number_confirmed, sender=CustomUser)
def handle_phone_confirmed(sender, user, phone_number, is_initial_confirmation, **kwargs):
if is_initial_confirmation:
print(f"User {user.id} confirmed their phone: {phone_number}")
else:
print(f"User {user.id} changed their phone to: {phone_number}")
email_confirmed
Emitted when a user successfully confirms their email address.
Parameters:
sender: The User model classuser: The user instance whose email was confirmedemail: The confirmed email address (str)is_initial_confirmation: True if this is the first confirmation, False if updating email
Example usage:
from django.dispatch import receiver
from moses.signals import email_confirmed
from moses.models import CustomUser
@receiver(email_confirmed, sender=CustomUser)
def handle_email_confirmed(sender, user, email, is_initial_confirmation, **kwargs):
if is_initial_confirmation:
print(f"User {user.id} confirmed their email: {email}")
else:
print(f"User {user.id} changed their email to: {email}")
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file django_moses-0.14.6.tar.gz.
File metadata
- Download URL: django_moses-0.14.6.tar.gz
- Upload date:
- Size: 29.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.2.1 CPython/3.13.8 Darwin/25.3.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
27331a55e548a3d9d141385676babc0bbf3505979cf01914f0db148f83c5e2ff
|
|
| MD5 |
e95976935627f42dd31340f352f5442c
|
|
| BLAKE2b-256 |
8995f15b77e41a8f11acd017f99274eceac9167fd10948d07c4702b281a34dbe
|
File details
Details for the file django_moses-0.14.6-py3-none-any.whl.
File metadata
- Download URL: django_moses-0.14.6-py3-none-any.whl
- Upload date:
- Size: 40.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.2.1 CPython/3.13.8 Darwin/25.3.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4bc970a746bb71f909bb5a771e7141b77b619dab5d24a197d7da3a5290d95ffe
|
|
| MD5 |
71be2a35279efe8f9ea06bd3a677b623
|
|
| BLAKE2b-256 |
1e7bb688cc2556aafe1a042112837e126a09f7670333000cb4db4704ff42d37b
|