Skip to main content

Authorize request with JSON Web Tokens

Project description

django_jwt_middleware

django_jwt_middleware is a package used for authorize django request with JSON Web Tokens

1. Installation

pip3 install django_jwt_middleware

or clone

git clone https://github.com/rizki4106/django_jwt_middleware.git

2. Example

with http cookie

If you store jwt key on cookie you can use @verify_jwt_cookie decorator

from django_jwt_middleware import verify_jwt_cookie
from rest_framework.decorators import api_view
from rest_framework.response import Response

@verify_jwt_cookie(cookie_name="example-token", jwt_key="supersecretkey", algorithm="HS256")
def hello_world(request):
    return Response(data={
        "message": "hello world"
    })

@verify_jwt_cookie takes 3 arguments

name type description
cookie_name string name of cookie that store your jwt token
jwt_key string jsonwebtoken secret key
algoritm string algorithm to decoded your jwt key default is HS256

With http headers

If you store jwt key http headers you can use @verify_jwt_header decorator

from django_jwt_middleware import verify_jwt_header
from rest_framework.decorators import api_view
from rest_framework.response import Response

@verify_jwt_header(header_name="example-token", jwt_key="supersecretkey", algorithm="HS256")
def hello_world(request):
    return Response(data={
        "message": "hello world"
    })

@verify_jwt_header takes 3 arguments

name type description
header_name string name of header that store your jwt token
jwt_key string jsonwebtoken secret key
algoritm string algorithm to decoded your jwt key default is HS256

3. Response

Type Description
success Will continue to request destination
failed Return http status code 403 with the message in it

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

django_jwt_middleware-1.0.1.tar.gz (3.3 kB view details)

Uploaded Source

Built Distribution

django_jwt_middleware-1.0.1-py3-none-any.whl (3.9 kB view details)

Uploaded Python 3

File details

Details for the file django_jwt_middleware-1.0.1.tar.gz.

File metadata

  • Download URL: django_jwt_middleware-1.0.1.tar.gz
  • Upload date:
  • Size: 3.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.8.2 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

File hashes

Hashes for django_jwt_middleware-1.0.1.tar.gz
Algorithm Hash digest
SHA256 14f0a37c9dc68017ba300a856a8614e77d5fa2041531505da2f9b6025904c5c3
MD5 92c4ec212753fc22307ed0542bfbe012
BLAKE2b-256 c75a06e238be3d1989fbabb9fb53718f0aaa3215c40d79d942973041d78a9304

See more details on using hashes here.

File details

Details for the file django_jwt_middleware-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: django_jwt_middleware-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 3.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.8.2 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

File hashes

Hashes for django_jwt_middleware-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 84a1c2239faf18965f39ce207c2d49b17ff655a88ebb2881b408b68ccbf87cbf
MD5 37ef42e1e23f06385d9438adf5fb8ab4
BLAKE2b-256 be5d56e0257fcccb446b1c0c5e931f26ee57b76c2fc239a9ff773cf1c1451ea1

See more details on using hashes here.

Supported by

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