Add multiple tokens support to django-rest-auth.
Project description
Rest Auth Multitoken
django-rest-auth is a great package for authentication with django, however it lacks the possibility of allowing a user to have multiple auth tokens. Thus a user has a single token shared across all his clients, and when he logs out from one client he gets logged out of all his clients.
rest-auth-multitoken solves this problem by adding multiple tokens support for a single user to django-rest-auth.
Installation
install rest-auth-multitoken
> pip install rest-auth-multitoken
Then in django's settings.py
:
add it to INSTALLED_APPS
:
# settings.py
INSTALLED_APPS = [
...
'rest_auth_multitoken',
...
]
add it to REST_FRAMEWORK
's config:
# settings.py
REST_FRAMEWORK = {
'DEFAULT_AUTHENTICATION_CLASSES': (
...
'rest_auth_multitoken.utils.MultiTokenAuthentication',
...
),
}
configure django-rest-auth
to use rest-auth-multitoken
:
# settings.py
REST_AUTH_TOKEN_CREATOR = 'rest_auth_multitoken.utils.multitoken_create'
REST_AUTH_TOKEN_MODEL = 'rest_auth_multitoken.models.Token'
Finally include the new MultitokenLogoutView
and MultitokenRegisterView
in urls.py
, just before django-rest-auth
's urls:
# urls.py
from rest_auth_multitoken.views import (
MultitokenRegisterView,
MultitokenLogoutView,
)
urlpatterns = [
...
path('api/auth/logout/', MultitokenLogoutView.as_view()),
path('api/auth/registration/', MultitokenRegisterView.as_view())
path('api/auth/registration/', include('rest_auth.registration.urls'))
path('api/auth/', include('rest_auth.urls')),
...
]
Now everytime a user logs in he'll get a new token, even if he's logged in from another client.
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
File details
Details for the file rest-auth-multitoken-0.2.2.tar.gz
.
File metadata
- Download URL: rest-auth-multitoken-0.2.2.tar.gz
- Upload date:
- Size: 4.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.4 CPython/3.9.0 Linux/5.4.0-58-generic
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8a6310e96e684c70ac1959ae9bf70dd95e82c70bcd4b9753d9cafb661be5d2a3 |
|
MD5 | d105ef4e6b8f97d63b1060ecfd6cd221 |
|
BLAKE2b-256 | cdefc9bd4fb100debeca19498c9d8f2ffc00c2772eae202b60922c079004410f |
File details
Details for the file rest_auth_multitoken-0.2.2-py3-none-any.whl
.
File metadata
- Download URL: rest_auth_multitoken-0.2.2-py3-none-any.whl
- Upload date:
- Size: 5.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.4 CPython/3.9.0 Linux/5.4.0-58-generic
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 700f3376520e2059805250c7982ea1ea324d34f9afdf37e9a00d2b65718508d6 |
|
MD5 | 4a55a97658fece6d06885d9959f52404 |
|
BLAKE2b-256 | addadbb6ae7b9d8405ab73f6d02d0b0d3e170ac5a0af24bd40a23e5ff92d6599 |