Skip to main content

Simple token based authentication for Django

Project description

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 Token

token = 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"}
)
```

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

django-token-0.1.1.tar.gz (4.1 kB view details)

Uploaded Source

File details

Details for the file django-token-0.1.1.tar.gz.

File metadata

  • Download URL: django-token-0.1.1.tar.gz
  • Upload date:
  • Size: 4.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for django-token-0.1.1.tar.gz
Algorithm Hash digest
SHA256 ee0ce33f71bc2b9bcb164b66c25336678441a9d668c8338206f337f814d4e40a
MD5 a8a69b7f964b0b9d6c46cab7f2d39fb1
BLAKE2b-256 e00440fa1dd8a081bcce1f9a15553f1aa937215e1c052f7998e13723957f7c88

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page