Skip to main content

REST authentication class to get token from HTTP body

Project description

Provide a Django REST Framework authentication class, to look for token in HTTP request’s body, instead of HTTP header.

This use case is uncommon and may be less secure, but some REST client application doesn’t let customize HTTP header, and hence, user cannot set Authorization header. One such client is Blynk Webhook Widget.

Install

pip3 install drf-body-token

DRF Body Token only supports Python 3.5+.

Usage

Add BodyTokenAuthentication to authentication_classes atrribute of your viewset. Example:

from drf_body_token.authentication import BodyTokenAuthentication

class MyAwesomeViewSet(GenericViewSet):
    authentication_classes = (TokenAuthentication, BodyTokenAuthentication)

You can also add it to REST_FRAMEWORK['DEFAULT_AUTHENTICATION_CLASSES'] settings, to make it available for every viewset.

By default, BodyTokenAuthentication looks for access_token field in request’s body. That body can be, for example:

{
    "name": "Cuckoo",
    "type": "bird",
    "access_token": "Vừng ơi mở ra"
}

If you want it to look for another field, add this to your settings.py file:

DRF_BODY_TOKEN_FIELD = 'your_field'

Project details


Release history Release notifications

Download files

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

Files for drf-body-token, version 0.1.0
Filename, size File type Python version Upload date Hashes
Filename, size drf_body_token-0.1.0-py3-none-any.whl (4.1 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size drf-body-token-0.1.0.tar.gz (2.8 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page