Git Product home page Git Product logo

django-token's Introduction

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

MIDDLEWARE_CLASSES = (
    # Other middleware
    'django_token.middleware.TokenMiddleware',
 )

Add the authenticaton backend to your AUTHENTICATION_BACKENDS

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.

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

import requests
response = requests.get(
    "http://myserver.com/api/stuff",
    headers={"Authorization": "token r454f2529f2cd27e1722e67a624b2b18335e6c21"}
)

django-token's People

Contributors

jasonbeverage avatar lig avatar

Stargazers

Fernando J Bardelli avatar

Watchers

James Cloos avatar Martín Gaitán avatar  avatar

Forkers

ucotta

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.