Django users authentication through SMS code
Project description
Django rest sms auth
- Authentication users in Django through SMS code
- Change user phone nuber
Requirements
- Python >= 3.0
- Django >= 2.0
- Celery
- Djangorestframework
- Django-phonenumber-field
Concept
- Client side send phone number (web/ios/android)
smsauth
validate phone number and createsms code
with life timesmsauth
sendsms code
(throughsms provider
)- User got
sms code
. Send it smsauth
validate{sms code + phone number}
- Send to client info (
jwt token
)
Notes
- Library use
celery
. Instruction - To use
twilio
install extra library - You may add your own provider inherit from
SMSProvider
Installation
pip install django-rest-sms-auth
If you want to use twilio
:
pip install twilio
settings.py
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
...
'sms_auth', # you have to add this
'sms_auth.providers.twilio' # if twilio provider
'sms_auth.providers.megafon' # if megafon provider
]
SMS_AUTH_SETTINGS = {
"SMS_CELERY_FILE_NAME": "run_celery", # your system celery file,
"SMS_AUTH_SUCCESS_KEY": "jwt_token", # property from user model
"SMS_AUTH_PROVIDER_FROM": "ex: +7542222222", # sms signature
# If twilio
"SMS_AUTH_ACCOUNT_SID": "Twilio SID"
"SMS_AUTH_AUTH_TOKEN": "Twilio token"
# If another provider
"SMS_AUTH_PROVIDER_LOGIN":"SMS provider login"
"SMS_AUTH_PROVIDER_PASSWORD": "SMS provider password"
}
Add celery
configuration file: Instruction
run migrations:
python manage.py makemigrations sms_auth && python manage.py migrate
urls.py
path('auth/', include('sms_auth.api.urls'))
Library is ready to use.
Usage
- Sign-in / sign-up:
POST /auth/sign-in/
body: {
"phone_number":"user phone number"
}
result: 200/400 response
- Code validation and get token:
POST /auth/auth/
body: {
"phone_number":"user phone number",
"code":sms_code
}
result: 200/400 response (with token)
- Change phone number:
POST /auth/change-phonenumber/
body: {
"new_phone_number":"user new phone number"
}
result: 200/400 response
Extra
To clear all expired sms codes
python manage.py clear_expired
Additional settings:
"SMS_AUTH_CODE_LEN": int (default: 4)
"SMS_DEBUG": bool (default: False)
"SMS_DEBUG_CODE": int (when debug, default 1111)
"SMS_USER_FIELD": "username"
"SMS_TIMELIFE": 60 # life time of each sms code
"SMS_CODE_NOT_FOUND": "Some text when code not found"
"SMS_WAIT_TIME": "Some text when sms was sended"
"SMS_REQUEST_SUCCESS": "Some text when success phone validatioin and sms sended to user"
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
django-rest-sms-auth-0.1.9.tar.gz
(11.8 kB
view hashes)
Built Distribution
Close
Hashes for django-rest-sms-auth-0.1.9.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 310c4fa64d6f1e23c6d3a9126f5ffeb93737280c8329af4708e2c4da01b41059 |
|
MD5 | 40fa37433e7ba81cc76a7a2c98027b54 |
|
BLAKE2b-256 | affebaf4999f4b62666b5b3bfb9a034a33a2271a0f435a844b7f1f36f04d2216 |
Close
Hashes for django_rest_sms_auth-0.1.9-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3b18458a1e02703281c28ee46568e05e9d1bd1ded4bc103a98c559d892e111e7 |
|
MD5 | 355632f4b32fe3af295603137ed5ed5b |
|
BLAKE2b-256 | 2503b6fc6ef62ba423d73cdd0311445b4faf79a03cebe18b34160be9569c8d4c |