Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jasonbeverage/django-token
Simple token based authentication for Django
https://github.com/jasonbeverage/django-token
Last synced: 4 months ago
JSON representation
Simple token based authentication for Django
- Host: GitHub
- URL: https://github.com/jasonbeverage/django-token
- Owner: jasonbeverage
- License: mit
- Created: 2014-10-22T13:51:01.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2023-09-11T13:51:16.000Z (over 1 year ago)
- Last Synced: 2024-10-14T23:30:56.354Z (4 months ago)
- Language: Python
- Size: 12.7 KB
- Stars: 12
- Watchers: 2
- Forks: 12
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
django-token
============Simple token based authentication for Django.
This draws inspiration from the Django Rest Framework token based authentication scheme but allows you to use it without using Django Rest Framework.
## Installing
Install from pip
```
sudo pip install django_token
```Add the middleware to your MIDDLEWARE_CLASSES
```python
MIDDLEWARE_CLASSES = (
# Other middleware
'django_token.middleware.TokenMiddleware',
)
```Add the authenticaton backend to your AUTHENTICATION_BACKENDS
```python
AUTHENTICATION_BACKENDS = (
'django.contrib.auth.backends.ModelBackend',
'django_token.backends.TokenBackend'
)
```## Creating tokens
You can create tokens for users using whatever workflow you'd like.
```python
from django_token.models import Tokentoken = Token.objects.create(user=myuser)
```If you REALLY want to reset all the tokens in your database, you can use the reset_tokens management command.
```
python manage.py reset_tokens
```This is useful when you've just installed django-token, but is otherwise dangerous :)
## Token in headers
The user's token should be passed in on every request in the HTTP authorization header.
Using [requests](http://docs.python-requests.org/en/latest/)
```python
import requests
response = requests.get(
"http://myserver.com/api/stuff",
headers={"Authorization": "token r454f2529f2cd27e1722e67a624b2b18335e6c21"}
)
```