Skip to main content

Simple JWT-based authentication designed for Django and Django Ninja. This package aims to provide a minimalistic approach to JWT authentication with the least amount of dependencies, making it easy to integrate and use in your projects.

Project description

django-ninja-jwt-basic

GitHub License Tests Codecov PyPI - Python Version PyPI - Versions from Framework Classifiers PyPI - Version Code style: black Linting: Ruff

Simple JWT-based authentication designed for Django and Django Ninja. This package aims to provide a minimalistic approach to JWT authentication with the least amount of dependencies, making it easy to integrate and use in your projects.

Installation

pip install django-ninja-jwt-basic

Configuration

Add the following settings to your Django settings:

JWT_SECRET_KEY = 'your_secret key' # Required

Add the app to your INSTALLED_APPS in your Django settings:

INSTALLED_APPS = [
    ...
    'django_ninja_jwt_basic',
    ...
]

Usage

Next, add router to your Django Ninja API and protect your endpoints

from ninja import NinjaAPI
from django_ninja_jwt_basic import JWTAuth

api = NinjaAPI(auth=JWTAuth())
api.add_router('/auth', 'django_ninja_jwt_basic.router')

This will add the following endpoint to your API:

  • /auth/login - POST - Login endpoint

    • Request body:

      {
          "username": "your_username",
          "password": "your_password"
      }
      
    • Response body:

      {
          "token": "your_access_token"
      }
      

If you don't want protect all endpoints, you can use JWTAuth class directly in your endpoints or routers like below:

from ninja import Router
from django_ninja_jwt_basic import JWTAuth

router = Router(auth=JWTAuth())

@router.get('/protected')
def protected(request):
    return {'message': 'This is a protected endpoint'}
from django_ninja_jwt_basic import JWTAuth

@api.get('/protected', auth=JWTAuth())
def protected(request):
    return {'message': 'This is a protected endpoint'}

You can find more information about protecting endpoints in the Django Ninja documentation

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_ninja_jwt_basic-0.1.2.tar.gz (3.5 kB view details)

Uploaded Source

Built Distribution

django_ninja_jwt_basic-0.1.2-py3-none-any.whl (4.7 kB view details)

Uploaded Python 3

File details

Details for the file django_ninja_jwt_basic-0.1.2.tar.gz.

File metadata

  • Download URL: django_ninja_jwt_basic-0.1.2.tar.gz
  • Upload date:
  • Size: 3.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.12.4 Linux/6.5.0-1023-azure

File hashes

Hashes for django_ninja_jwt_basic-0.1.2.tar.gz
Algorithm Hash digest
SHA256 f811755ac43e9b61750bb148e71d789193f3717685670c7f3fcbffe08c05afa6
MD5 6a926d409d3a0bda0d385a17bd8d2d8e
BLAKE2b-256 70f2f0683bc60f6079766a39b3dd1c36d6581a5ab4d9d08ab54999fccbae01d7

See more details on using hashes here.

File details

Details for the file django_ninja_jwt_basic-0.1.2-py3-none-any.whl.

File metadata

File hashes

Hashes for django_ninja_jwt_basic-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 eca2680eae29794d41ea427885ee9c4c1ce0350f3116b5f8100ec26499b1f855
MD5 e76a2ac05aefe25149fd880f5a271cf6
BLAKE2b-256 8077252cb29ccdafbd026020734991b896b82c833361225522f676f5ebdaf7c6

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