This is a pre-production deployment of Warehouse. Changes made here affect the production instance of PyPI (pypi.python.org).
Help us improve Python packaging - Donate today!

Simple Key and Token authentication for Django.

Project Description

Key authentication for django. Can be used with django-piston easily.

Based on https://github.com/scoursen/django-apikey.

Installation

pip install django-apikey

Configuration

Add ‘apikey’ to your settings.py:

INSTALLED_APPS = (
...
'apikey',
....
)

A Question

What is a Token and a Key? and which are the differences between them?

Token

A Token is generated with:

Token.objects.create(user)

and it can be used to authenticate requests with Django-Piston as long as it remain active, which is configured in settings.py:

TOKEN_VALID_SECONDS = 3600

The header used to send the token is configured in settings.py with:

TOKEN_AUTH_HEADER = 'X-Auth-Token'

To ask for a token in a resource handler use it like this:

from apikey.auth import TokenAuthentication
from piston.handler import BaseHandler
from piston.resource import Resource
from app.models import Item

class ItemHandler(BaseHandler):
    allowed_methods = ('GET', )
    fields = ('name', 'id')
    model = Item

    def read(self, request):
        return Item.objects.all()

handler = Resource(
    handler=ItemHandler, authentication=TokenAuthentication())

The token remains active TOKEN_VALID_SECONDS after each request, and it should be created in a request authenticated with the username/email and password/key, or Basic, Digest.

ApiKey

ApiKey is basically a key used to authenticate the requests that replace an email/username and password in all the API request.

You can change the authorization header by setting the APIKEY_AUTHORIZATION_HEADER in settings.py:

APIKEY_AUTHORIZATION_HEADER = 'App-Authorization'

To add api authentication with piston write this in your handlers:

from apikey.auth import ApiKeyAuthentication
from piston.handler import BaseHandler
from piston.resource import Resource
from app.models import Item

class ItemHandler(BaseHandler):
    allowed_methods = ('GET', )
    fields = ('name', 'id')
    model = Item

    def read(self, request):
        return Item.objects.all()

handler = Resource(
    handler=ItemHandler, authentication=ApiKeyAuthentication())

Thanks

This project is base on the one of Steve Coursen https://github.com/scoursen/django-apikey but with several simplifications, and adds.

License

This software is licensed under the New BSD License.

Release History

Release History

This version
History Node

0.2.0

History Node

0.1.8

History Node

0.1.7

History Node

0.1.6

History Node

0.1.5

History Node

0.1.4

History Node

0.1.3

History Node

0.1.2

History Node

0.1.1

History Node

0.1.0

Download Files

Download Files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
django-apikey-0.2.0.tar.gz (3.3 kB) Copy SHA256 Checksum SHA256 Source Jul 5, 2011

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting