Getting started¶
JWT Ninja is a standard Django app. Install it, run migrations, and mount the router.
Install¶
Requires Python 3.12+ and Django 5.2.16 through 6.1 (>=5.2.16,<6.2).
Asymmetric algorithms
Asymmetric signing algorithms (RS*, ES*, PS*, EdDSA) need PyJWT's cryptography extra:
Quick start¶
1. Add jwt_ninja to your INSTALLED_APPS:
2. Run migrations to create the Session table:
3. Mount the router on your Ninja API and register the error handler:
api.py
from ninja import NinjaAPI
from jwt_ninja import APIError
from jwt_ninja.api import router as auth_router
from jwt_ninja.handlers import error_handler
api = NinjaAPI()
api.add_router("auth/", auth_router)
api.add_exception_handler(APIError, error_handler)
This gives you /auth/login/, /auth/refresh/, /auth/sessions/, /auth/sessions/{id}/, /auth/logout/, and /auth/logout/all/.
Next steps¶
- Protect your views with
JWTAuth. - Give users a session list with per-device sign-out: Sessions & devices.
- Read the endpoint reference.
- Review the configuration options.
- Before you go live, walk the deployment checklist.