Simple token based authentication for your APIs
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
dist
vanguard.egg-info
vanguard
LICENSE
MANIFEST.in
README.md
manage.py
requirements.txt
setup.py

README.md

Vanguard is a simple API authentication library for Django REST Framework

Quick start

  1. Install vanguard using pip install vanguard

  2. Add "vanguard" to your INSTALLED_APPS setting like this::

INSTALLED_APPS = [
            ...
            'rest_framework',
            'vanguard',
            ...
        ]
  1. Include the vanguard URLconf in your project urls.py like this::
from django.conf.urls import include
:
url(r'^vanguard/', include('vanguard.urls')),
  1. Run python manage.py migrate to create the vanguard models.

  2. Available vanguard endpoints

Signup [vanguard/, vanguard/signup]
Login [vanguard/login]
Password Retieval [vanguard/forgotpassword]
Logout [vanguard/logout]
  1. Use @validate_token as the inner most annotation for any API end point method you wanna authenticate
from rest_framework.decorators import api_view, renderer_classes
from rest_framework.renderers import JSONRenderer, BrowsableAPIRenderer, status
from rest_framework.response import Response
:
from vanguard.utils import validate_token
:
.
@api_view(['GET', 'POST'])
@renderer_classes((JSONRenderer, BrowsableAPIRenderer,))
@validate_token
def my_api(request):
    #On successful authentication, HTTP_TOKEN's value will be replaced by
    #authenticated user's email
    user_email=request.META['HTTP_TOKEN']
    :
    return Response({'Authenticated User': request.META['HTTP_TOKEN']}, status=status.HTTP_200_OK)