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

  1. Add the following settings to your Django settings:

    JWT_SECRET_KEY = 'your_secret key' # Required
    
  2. 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')

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

Uploaded Source

Built Distribution

django_ninja_jwt_basic-0.1.0-py3-none-any.whl (4.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: django_ninja_jwt_basic-0.1.0.tar.gz
  • Upload date:
  • Size: 3.3 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.0.tar.gz
Algorithm Hash digest
SHA256 82adf64728f61bcbb5b3d7fcfd1d46de739f5fc97b5429690c2a164bcd86ec34
MD5 695900970768d7f76d055da28983ab4b
BLAKE2b-256 5d9fa4ece61d88ac78fcd624b778e9ee10473929dcf64336aa7bf96f5e137f90

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for django_ninja_jwt_basic-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b9482f72e6e1792a949d69a11207485f5e22f479490f271b352b5b96698b93da
MD5 65b924f85e68889d6ad33554ab6fecf8
BLAKE2b-256 2519239d20c34e4d7a9bc590dd894d80862f917004e62a004fc817013597b7b8

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