Version of Django REST Framework auth Token allowing multiple Tokens per User.
Project description
djangorestframework-multitoken
Version of Django REST Framework auth Token allowing multiple Tokens per User.
Usage
Install:
pip install djangorestframework-multitoken
Enable:
# settings.py
INSTALLED_APPS = [
...
'rest_framework_multitoken',
...
]
Migrate:
python manage.py migrate
Sync:
To create MultiTokens from existing Django REST Framework auth Tokens run:
python manage.py multitoken_sync
If you want to switch back to regular Django REST Framework auth Tokens run:
# WARNING be careful as data may be lost
python manage.py multitoken_sync --backwards
WARNING: The --backwards sync may lose data if you have created multiple MultiToken instances for a User.
Only one of the MultiToken instances can be moved back to a regular Django REST Framework auth Token.
The MultiToken selected to be moved back will be the primary token which is the newest active token for the User.
Note: to run either of those commands you must have both rest_framework.authtoken and rest_framework_multitoken in INSTALLED_APPS and respective database migrations applied.
Enjoy:
View and manage Tokens in the Django Admin under Multi Token.
Use MultiTokenAuthentication globally or on a per-view basis.
# settings.py - use MultiTokenAuthentication globally
REST_FRAMEWORK = {
'DEFAULT_AUTHENTICATION_CLASSES': [
...
'rest_framework_multitoken.authentication.MultiTokenAuthentication',
...
],
...
}
# views.py - use MultiTokenAuthentication on a per-view basis
from rest_framework_multitoken.authentication import MultiTokenAuthentication
class MyView(APIView):
authentication_classes = [MultiTokenAuthentication]
...
Access the MultiToken instances for a User with the get_user_primary_token utility method or the multi_tokens backwards relationship.
# get_user_primary_token utility method
from rest_framework_multitoken.utils import get_user_primary_token
multi_token = get_user_primary_token(user)
# backwards relationship
multi_tokens = user.multi_tokens.filter(is_active=True)
License
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file djangorestframework-multitoken-0.1.tar.gz.
File metadata
- Download URL: djangorestframework-multitoken-0.1.tar.gz
- Upload date:
- Size: 5.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ffe064d4480e90eacbb8cc059f047c0756dbac6ee72e2c5e9911c61467ca8e20
|
|
| MD5 |
bcc00d14a31f476712dd8287e71817c5
|
|
| BLAKE2b-256 |
96f9e28b800f96e81b4b8810e99a7711a4153b29340d6222e10611a919fa6f4b
|
File details
Details for the file djangorestframework_multitoken-0.1-py3-none-any.whl.
File metadata
- Download URL: djangorestframework_multitoken-0.1-py3-none-any.whl
- Upload date:
- Size: 8.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
70636b314065bdf17c7d0dc0ed2ac4c17f40791ec51131f416a4073dc630a617
|
|
| MD5 |
85c43a3f098333697e4d902c745432e8
|
|
| BLAKE2b-256 |
9098f74792209d13bdfdfb7f1d61bc50743bdb7b1aff4a2d30854eb0bcf97f6b
|