Django users authentication through SMS code
Project description
Django rest sms auth
- Authentication users
- Change phone number
- Providers:
- Megafon
- Smsaero
- Twilio
Requirements
- Python >= 3.0
- Django >= 2.0
- Celery
- Djangorestframework
- Django-phonenumber-field
Concept
- Client send phone number
smsauth
validate and createsms code
sms provider
send digit code- Client send
{sms code + phone number}
- Response 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
After your call previous endpoint: /auth/auth
and send new phone number with code.
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",
"SMS_AUTH_DEBUG_PHONE_NUMBER": phone number with always SMS_DEBUG_CODE
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
File details
Details for the file django-rest-sms-auth-0.1.22.tar.gz
.
File metadata
- Download URL: django-rest-sms-auth-0.1.22.tar.gz
- Upload date:
- Size: 12.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.57.0 CPython/3.8.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4bbfeea387ce958ea106b036b4e26c8e173994067eeb03e4eb5e52c2a3d67f11 |
|
MD5 | 13d9b4ff0774102c3bfcacef03e7a57b |
|
BLAKE2b-256 | b11b983f7720bbf320bb85dd0d9a0211a70cbf7c8f29fd5bff6dd93101378aa0 |
Provenance
File details
Details for the file django_rest_sms_auth-0.1.22-py2-none-any.whl
.
File metadata
- Download URL: django_rest_sms_auth-0.1.22-py2-none-any.whl
- Upload date:
- Size: 19.1 kB
- Tags: Python 2
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.57.0 CPython/3.8.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e89e1562ce8c6b9723049a5a9220893f443b54625ba3fb9950a8e3108c45e56c |
|
MD5 | 32009b41e6d266f8cfd870d1ed16db7f |
|
BLAKE2b-256 | 824beba5f6e31bfaa164e6c028eaf0ac042faf4f49608da0b2a2377acec16491 |