Expiring token with expiration time update for Django Rest Framework
Project description
Django Expiring Token adds token expiration on token authentication and extends the expiration time on each authenticated request.
Django Expiring Token provides a very lightweight extension to DRF’s existing token authentication. It implements the following functionalities:
Tokens expire after the set time.
On each authenticated request, the expiration time is updated by the set time.
Quick start
Do NOT add “restframework.authtoken” to you INSTALLED_APPS.
Add “drf_expiring_token” to your INSTALLED_APPS setting like this:
INSTALLED_APPS = [ ... 'drf_expiring_token', ]
Include the polls URLconf in your project urls.py like this:
path('custom-url/', include('drf_expiring_token.urls')),
Add the expiration time in settings.py:
EXPIRING_TOKEN_DURATION=timedelta(hours=1) # Any timedelta setting can be used! If not set, the default value is 1 day
Add the default authentication class in REST_FRAMEWORK settings in settings.py:
REST_FRAMEWORK = { 'DEFAULT_AUTHENTICATION_CLASSES': ( ... 'drf_expiring_token.authentication.ExpiringTokenAuthentication', ... ), }
Run python manage.py migrate to create package migrations
Start the development server an you are good to go.
Tests
This build is tested against Python versions 3.4, 3.5, 3,6 with Django versions 2.0.8+
To run tests
Install coverage:
pip install coverage
Run tests:
coverage run runtest.py
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
Hashes for drf_expiring_token-1.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7a8c482a17f3c36cea98955c90eb55688a202d62016200b05edaab9f45dc04fe |
|
MD5 | 01267e6da33eab3faec71c9079e537dc |
|
BLAKE2b-256 | 1bf986992e790657b0cf283ba906930ebc1f517cb71897b0634d31930c66c4dc |