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

Uploaded Source

Built Distribution

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

Uploaded Python 3

File details

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

File metadata

  • Download URL: django_ninja_jwt_basic-0.1.1.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-1022-azure

File hashes

Hashes for django_ninja_jwt_basic-0.1.1.tar.gz
Algorithm Hash digest
SHA256 6731c8b490383e74d687b8e7cf09a22e292f391d36c4a5660421db6b5ec5bf51
MD5 961f2708e91110334e4f81c3e7fb7c39
BLAKE2b-256 d6e0cf710774d5cae6c9561977860e63faed559135fa1195671f051b5242a3e9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for django_ninja_jwt_basic-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 f66aa7d83bde2f33487ad0b478b711ced3423a7e36936ddb0ebc526dafa3981c
MD5 b96933752bc484b7cfbbd4a7f0baec6a
BLAKE2b-256 9ee76e2c00701ab78cb17d9af9ceeada903b5e9e03360ffc036be01ab1a3bead

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