Skip to main content

An extension of django rest frameworks token auth, providing multiple authentication tokens per user

Project description

Django Rest Multi Token Auth

This django app is an extension for the Django Rest Framework (Version 3.4+). It tries to overcome the limitation of Token Authentication, which only uses a single token per user.

How to use

Install:

pip install django-rest-multitokenauth

Add 'django_rest_multitokenauth' to your INSTALLED_APPS in your Django settings file:

INSTALLED_APPS = (
    ...
    'django.contrib.auth',
    ...
    'rest_framework',
    ...
    'django_rest_multitokenauth',
    ...
)

Configure Django REST Framework to use 'django_rest_multitokenauth.coreauthentication.MultiTokenAuthentication':

REST_FRAMEWORK = {
    ...
    'DEFAULT_AUTHENTICATION_CLASSES': [
        ...
        'django_rest_multitokenauth.coreauthentication.MultiTokenAuthentication',
        ...
    ],
    ...
}

And add the auth urls to your Django url settings:

from django.conf.urls import url, include


urlpatterns = [
    ...
    url(r'^api/auth/', include('django_rest_multitokenauth.urls', namespace='multi_token_auth')),
    ...
]    

The following endpoints are provided:

  • login - takes username and password; on success an auth token is returned
  • logout

Signals

  • pre_auth(username, password) - Fired when an authentication (login) is starting
  • post_auth(user) - Fired on successful auth

Tests

See folder tests/. Basically, all endpoints are covered with multiple unit tests.

Use this code snippet to run tests:

pip install tox
tox

Cache Backend

If you want to use a cache for the session store, you can install django-memoize and add 'memoize' to INSTALLED_APPS.

Then you need to use CachedMultiTokenAuthentication instead of MultiTokenAuthentication.

pip install django-memoize

Django Compatibility Matrix

If your project uses an older verison of Django or Django Rest Framework, you can choose an older version of this project.

This Project Python Version Django Version Django Rest Framework
1.3.* 2.7, 3.4+ 1.11, 2.0+ 3.6, 3.7, 3.8
1.2.* 2.7, 3.4+ 1.8, 1.11, 2.0+ 3.6, 3.7, 3.8

Changelog / Releases

All releases should be listed in the releases tab on github.

See CHANGELOG.md for a more detailed listing.

License

This project is published with the BSD 3 Clause License. See https://choosealicense.com/licenses/bsd-3-clause-clear/ for more information about what this means.

Project details


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-multitokenauth-1.3.2.tar.gz (8.4 kB view details)

Uploaded Source

Built Distribution

django_rest_multitokenauth-1.3.2-py2.py3-none-any.whl (11.2 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file django-rest-multitokenauth-1.3.2.tar.gz.

File metadata

  • Download URL: django-rest-multitokenauth-1.3.2.tar.gz
  • Upload date:
  • Size: 8.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.15.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/45.0.0 requests-toolbelt/0.9.1 tqdm/4.41.1 CPython/3.5.2

File hashes

Hashes for django-rest-multitokenauth-1.3.2.tar.gz
Algorithm Hash digest
SHA256 bd9f811b212cec29a95d015e51954cb700dccead460c126db6fc27979c9bf18e
MD5 561de709dec7eab00897fc0ee0dec08b
BLAKE2b-256 067d427d382d576d8518aca8b560ce349c6ef4324f45e573d92196d6a7554787

See more details on using hashes here.

Provenance

File details

Details for the file django_rest_multitokenauth-1.3.2-py2.py3-none-any.whl.

File metadata

  • Download URL: django_rest_multitokenauth-1.3.2-py2.py3-none-any.whl
  • Upload date:
  • Size: 11.2 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.15.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/45.0.0 requests-toolbelt/0.9.1 tqdm/4.41.1 CPython/3.5.2

File hashes

Hashes for django_rest_multitokenauth-1.3.2-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 6e41b6f630e94794955b109e6e174d836bda507cd8ff857c6ef822a2a6f30429
MD5 ba6a22aeae2239d08692f6dd5b495199
BLAKE2b-256 5683439f8a30325c6fd09058b6d9c7a3448723cc0ff534529a1d2b0ae7ad0182

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page