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. 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 include
from django.urls import re_path
urlpatterns = [
...
re_path(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 returnedlogout
Signals
pre_auth(username, password)
- Fired when an authentication (login) is startingpost_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.5.* | 3.7+ | 3.2, 4.0, 4.1 | 3.12, 3.13 |
1.4.* | 3.6+ | 2.2, 3.2 | 3.9, 3.10, 3.11, 3.12 |
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 |
Make sure to use at least DRF 3.10
when using Django 3.0
or newer.
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
Built Distribution
File details
Details for the file django-rest-multitokenauth-1.5.0.tar.gz
.
File metadata
- Download URL: django-rest-multitokenauth-1.5.0.tar.gz
- Upload date:
- Size: 10.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | afc2be0873e93f00e4b37024adf9c0b0ae678dc3c9f7230bd19c581289d225e8 |
|
MD5 | 0ad404e2010e8058759850ee7ef9e2ff |
|
BLAKE2b-256 | fab8e781abfad6d49103935ab0226373768d66af29261854a5021b33d69563c4 |
Provenance
File details
Details for the file django_rest_multitokenauth-1.5.0-py2.py3-none-any.whl
.
File metadata
- Download URL: django_rest_multitokenauth-1.5.0-py2.py3-none-any.whl
- Upload date:
- Size: 11.4 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 183593ba9bdd3284dca28c51b7a3250d472a090225cd5648f609b218d8b7898a |
|
MD5 | cbb2b0f84b11bbb1e1818c397bbbb185 |
|
BLAKE2b-256 | 46938d1da70ea0c7e5a1a5c4c43e20b799fd72a984061d8780f92883f58501dc |