Add secure token to django-rest-framework
Project description
Add “drf_secure_token” to your INSTALLED_APPS setting like this:
INSTALLED_APPS = [ ... 'rest_framework', 'drf_secure_token', ]
Add following lines to your settings.py:
REST_FRAMEWORK = { 'DEFAULT_AUTHENTICATION_CLASSES': [ 'rest_framework.authentication.BasicAuthentication', 'drf_secure_token.authentication.SecureTokenAuthentication', ] }
For updating token add this middleware to your MIDDLEWARE_CLASSES:
MIDDLEWARE_CLASSES = ( ... 'drf_secure_token.middleware.UpdateTokenMiddleware', )
Add UPDATE_TOKEN to your ‘dev’ settings if you don’t want to update token in DEBUG mode:
UPDATE_TOKEN = False
Add TOKEN_AGE to your settings:
TOKEN_AGE = 60*10 # 10 min
(Optional) To cleanup dead tokens celery can be used. Way to enable depends from celery version
6.1 Celery 4, just enable it with settings:
REMOVE_TOKENS_THROUGH_CELERY = True
6.2 Celery 5, add periodic task manually:
@app.on_after_finalize.connect def setup_periodic_tasks(sender, **kwargs): from drf_secure_token.tasks import DELETE_OLD_TOKENS app.conf.beat_schedule.update({ 'drf_secure_token.tasks.delete_old_tokens': DELETE_OLD_TOKENS, })
Run python manage.py migrate to create the drf_secure_token models.
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
drf-secure-token-1.2.0.tar.gz
(6.4 kB
view hashes)
Built Distribution
Close
Hashes for drf_secure_token-1.2.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 38bdc2709b0e1419a05a7807cf56e57923d1131a56ca3241ed6f6866316c0f41 |
|
MD5 | 619d7f8ab85a2aeb3013ed1d7eeeae31 |
|
BLAKE2b-256 | 12186cbc424e00c08865e712d2d89206ede56a1adbceecb90e9f37b54668f956 |