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
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
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
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6731c8b490383e74d687b8e7cf09a22e292f391d36c4a5660421db6b5ec5bf51 |
|
MD5 | 961f2708e91110334e4f81c3e7fb7c39 |
|
BLAKE2b-256 | d6e0cf710774d5cae6c9561977860e63faed559135fa1195671f051b5242a3e9 |
File details
Details for the file django_ninja_jwt_basic-0.1.1-py3-none-any.whl
.
File metadata
- Download URL: django_ninja_jwt_basic-0.1.1-py3-none-any.whl
- Upload date:
- Size: 4.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 CPython/3.12.4 Linux/6.5.0-1022-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f66aa7d83bde2f33487ad0b478b711ced3423a7e36936ddb0ebc526dafa3981c |
|
MD5 | b96933752bc484b7cfbbd4a7f0baec6a |
|
BLAKE2b-256 | 9ee76e2c00701ab78cb17d9af9ceeada903b5e9e03360ffc036be01ab1a3bead |