Skip to main content

A simple API authentication library for Django REST Framework

Project description

Vanguard is a simple API authentication library for Django REST Framework

Quick start
-----------
0. Install `vanguard` using `pip`
`pip install vanguard`

1. Add "vanguard" to your INSTALLED_APPS setting like this::
```
INSTALLED_APPS = [
...
'rest_framework',
'vanguard',
...
]
```

2. Include the vanguard URLconf in your project urls.py like this::
```
from django.conf.urls import include
:
url(r'^vanguard/', include('vanguard.urls')),
```

3. Run `python manage.py migrate` to create the vanguard models.

4. Available vanguard endpoints
```
Signup [vanguard/, vanguard/signup]
Login [vanguard/login]
Password Retieval [vanguard/forgotpassword]
Logout [vanguard/logout]
```

5. 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)
```

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

vanguard-0.0.2.tar.gz (6.7 kB view details)

Uploaded Source

File details

Details for the file vanguard-0.0.2.tar.gz.

File metadata

  • Download URL: vanguard-0.0.2.tar.gz
  • Upload date:
  • Size: 6.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for vanguard-0.0.2.tar.gz
Algorithm Hash digest
SHA256 dfebcbd345f3ce887f9401ccee5cba98bea966aa1e9675d16761b4dab5f9132a
MD5 e96a366f927f92439125ff99fa80d2d3
BLAKE2b-256 808910c075d4a8254ba7baf4caf16877ee365c5c655d66eceda36c095b4c9008

See more details on using hashes here.

Supported by

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