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
Install:
```bash
pip install django-rest-multitokenauth
```
Add ``'django_rest_multitokenauth'`` to your ``INSTALLED_APPS`` in your Django settings file:
```python
INSTALLED_APPS = (
...
'django.contrib.auth',
...
'rest_framework',
...
'django_rest_multitokenauth',
...
)
```
Configure Django REST Framework to use ``'django_rest_multitokenauth.coreauthentication.MultiTokenAuthentication'``:
```python
REST_FRAMEWORK = {
...
'DEFAULT_AUTHENTICATION_CLASSES': [
...
'django_rest_multitokenauth.coreauthentication.MultiTokenAuthentication',
...
],
...
}
```
And add the auth urls to your 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
```
## Django Compatibility Matrix
If your project uses an older verison of Django or Django Rest Framework, you can choose an older version of this project.
| This Project | Python Version | Django Version | Django Rest Framework |
|--------------|----------------|----------------|-----------------------|
| 1.3.* | 2.7, 3.4+ | 1.11, 2.0+ | 3.6, 3.7, 3.8 |
| 1.2.* | 2.7, 3.4+ | 1.8, 1.11, 2.0+| 3.6, 3.7, 3.8 |
## Changelog / Releases
All releases should be listed in the [releases tab on github](https://github.com/anx-ckreuzberger/django-rest-multiauthtoken/releases).
See [CHANGELOG.md](CHANGELOG.md) for a more detailed listing.
## License
This project is published with the [BSD 3 Clause License](LICENSE). See [https://choosealicense.com/licenses/bsd-3-clause-clear/](https://choosealicense.com/licenses/bsd-3-clause-clear/) for more information about what this means.
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
Install:
```bash
pip install django-rest-multitokenauth
```
Add ``'django_rest_multitokenauth'`` to your ``INSTALLED_APPS`` in your Django settings file:
```python
INSTALLED_APPS = (
...
'django.contrib.auth',
...
'rest_framework',
...
'django_rest_multitokenauth',
...
)
```
Configure Django REST Framework to use ``'django_rest_multitokenauth.coreauthentication.MultiTokenAuthentication'``:
```python
REST_FRAMEWORK = {
...
'DEFAULT_AUTHENTICATION_CLASSES': [
...
'django_rest_multitokenauth.coreauthentication.MultiTokenAuthentication',
...
],
...
}
```
And add the auth urls to your 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
```
## Django Compatibility Matrix
If your project uses an older verison of Django or Django Rest Framework, you can choose an older version of this project.
| This Project | Python Version | Django Version | Django Rest Framework |
|--------------|----------------|----------------|-----------------------|
| 1.3.* | 2.7, 3.4+ | 1.11, 2.0+ | 3.6, 3.7, 3.8 |
| 1.2.* | 2.7, 3.4+ | 1.8, 1.11, 2.0+| 3.6, 3.7, 3.8 |
## Changelog / Releases
All releases should be listed in the [releases tab on github](https://github.com/anx-ckreuzberger/django-rest-multiauthtoken/releases).
See [CHANGELOG.md](CHANGELOG.md) for a more detailed listing.
## License
This project is published with the [BSD 3 Clause License](LICENSE). See [https://choosealicense.com/licenses/bsd-3-clause-clear/](https://choosealicense.com/licenses/bsd-3-clause-clear/) for more information about what this means.
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
Close
Hashes for django-rest-multitokenauth-1.3.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9510bba30f4a973e97597c8fda856195f6127dfb1db8b0d2cdc64056d09bd245 |
|
MD5 | 0745ca9263998032b4d20dd861ca6a17 |
|
BLAKE2b-256 | ad88ab857a35fcdfa98ef76237c3ae82a025753fc16b2495a5c05b6ec2b767b6 |