Skip to main content
Join the official 2019 Python Developers SurveyStart the survey!

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:

  1. Tokens expire after the set time.
  2. On each authenticated request, the expiration time is updated by the set time.

Quick start

  1. Do NOT add “restframework.authtoken” to you INSTALLED_APPS.

  2. Add “django_expiring_token” to your INSTALLED_APPS setting like this:

    INSTALLED_APPS = [
        ...
        'django_expiring_token',
    ]
    
  3. Include the polls URLconf in your project urls.py like this:

    path('custom-url/', include('django_expiring_token.urls')),
    
  4. 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
    
  5. Add the default authentication class in REST_FRAMEWORK settings in settings.py:

    REST_FRAMEWORK = {
        'DEFAULT_AUTHENTICATION_CLASSES': (
            ...
            'django_expiring_token.authentication.ExpiringTokenAuthentication',
            ...
        ),
    }
    
  6. Run python manage.py migrate to create package migrations

  7. 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

  1. Install coverage:

    pip install coverage
    
  2. Run tests:

    coverage run runtest.py
    

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for django-expiring-token, version 1.0.2
Filename, size File type Python version Upload date Hashes
Filename, size django_expiring_token-1.0.2-py3-none-any.whl (8.3 kB) File type Wheel Python version py3 Upload date Hashes View hashes
Filename, size django-expiring-token-1.0.2.tar.gz (5.7 kB) File type Source Python version None Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page