Django app that that implements a cached version of rest_framework
token authentication.
-
Install using pip:
pip install -e git+https://github.com/ueni-ltd/[email protected]#egg=drf_cached_token
-
Add
drf_cached_token
toINSTALLED_APPS
insettings.py
:INSTALLED_APPS = ( ... 'drf_cached_token', ... )
-
Configure the app in
settings.py
, bellow are shown the default settings:DRF_CACHED_TOKEN = { 'TIMEOUT': None, 'BACKEND': 'default', 'REGISTER_SIGNALS': True, 'TOKEN_QUERY_PARAM': 'api_token', }
-
TIMEOUT
- timeout for keys in the cache specified in seconds. -
BACKEND
- name of the django cache used to store the tokens. -
REGISTER_SIGNALS
- boolean indicating wheter the app should register signals that update the cache when the token or user objects are updated, created or deleted. -
TOKEN_QUERY_PARAM
- name of the query parameter from which the token will be taken, when usingQueryParamsTokenAuthentication
.
-
-
You can set it as default in your
rest_framework
settings:REST_FRAMEWORK = { ... 'DEFAULT_AUTHENTICATION_CLASSES': ( 'drf_cached_token.authentication.CachedTokenAuthentication', ), ... }
-
Or just use it in your view:
from rest_framework.viewsets import ModelViewSet from drf_cached_token.authentication import CachedTokenAuthentication class MyVieSet(ModelViewSet): authentication_classes = (CachedTokenAuthentication,) ...