An extension of django rest frameworks token auth, providing multiple tokens per user
Project description
# Django Rest Multi Token Auth
This django app is an extension for the Django Rest Framework (Version 3.4+).
It tries to overcome the limitation of Token Authentication, which only uses a single
token per user.
## How to use
Django settings file:
```python
INSTALLED_APPS = (
...
'django.contrib.auth',
...
'rest_framework',
...
'django_rest_multitokenauth',
...
)
```
Django REST Framework Settings:
```python
REST_FRAMEWORK = {
...
'DEFAULT_AUTHENTICATION_CLASSES': [
...
'django_rest_multitokenauth.coreauthentication.MultiTokenAuthentication',
...
],
...
}
```
Django url settings:
```python
from django.conf.urls import url, include
urlpatterns = [
...
url(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 returned
* `logout`
## Signals
* ``pre_auth(username, password)`` - Fired when an authentication (login) is starting
* ``post_auth(user)`` - Fired on successful auth
## Tests
See folder [tests/](tests/). Basically, all endpoints are covered with multiple
unit tests.
Use this code snippet to run tests:
```bash
pip install tox
tox
```
## Cache Backend
If you want to use a cache for the session store, you can install [django-memoize](https://pythonhosted.org/django-memoize/) and add `'memoize'` to `INSTALLED_APPS`.
Then you need to use ``CachedMultiTokenAuthentication`` instead of ``MultiTokenAuthentication``.
```bash
pip install django-memoize
```
This django app is an extension for the Django Rest Framework (Version 3.4+).
It tries to overcome the limitation of Token Authentication, which only uses a single
token per user.
## How to use
Django settings file:
```python
INSTALLED_APPS = (
...
'django.contrib.auth',
...
'rest_framework',
...
'django_rest_multitokenauth',
...
)
```
Django REST Framework Settings:
```python
REST_FRAMEWORK = {
...
'DEFAULT_AUTHENTICATION_CLASSES': [
...
'django_rest_multitokenauth.coreauthentication.MultiTokenAuthentication',
...
],
...
}
```
Django url settings:
```python
from django.conf.urls import url, include
urlpatterns = [
...
url(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 returned
* `logout`
## Signals
* ``pre_auth(username, password)`` - Fired when an authentication (login) is starting
* ``post_auth(user)`` - Fired on successful auth
## Tests
See folder [tests/](tests/). Basically, all endpoints are covered with multiple
unit tests.
Use this code snippet to run tests:
```bash
pip install tox
tox
```
## Cache Backend
If you want to use a cache for the session store, you can install [django-memoize](https://pythonhosted.org/django-memoize/) and add `'memoize'` to `INSTALLED_APPS`.
Then you need to use ``CachedMultiTokenAuthentication`` instead of ``MultiTokenAuthentication``.
```bash
pip install django-memoize
```
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
File details
Details for the file django-rest-multitokenauth-1.2.1.tar.gz
.
File metadata
- Download URL: django-rest-multitokenauth-1.2.1.tar.gz
- Upload date:
- Size: 10.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | caa44a21a741151dacab679848d192821963d8432c6f6afcae2098db26096cd3 |
|
MD5 | 3c846666d97648a0b824e2b32266755f |
|
BLAKE2b-256 | 16d6c8cae4f80b76245d17c5f9ad586cc49116f73e2bf758909c0aac0f0e54c0 |