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
Hashes for djangorestframework-multitoken-0.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | ffe064d4480e90eacbb8cc059f047c0756dbac6ee72e2c5e9911c61467ca8e20 |
|
MD5 | bcc00d14a31f476712dd8287e71817c5 |
|
BLAKE2b-256 | 96f9e28b800f96e81b4b8810e99a7711a4153b29340d6222e10611a919fa6f4b |
Hashes for djangorestframework_multitoken-0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 70636b314065bdf17c7d0dc0ed2ac4c17f40791ec51131f416a4073dc630a617 |
|
MD5 | 85c43a3f098333697e4d902c745432e8 |
|
BLAKE2b-256 | 9098f74792209d13bdfdfb7f1d61bc50743bdb7b1aff4a2d30854eb0bcf97f6b |