Django authentication uses Django’s built-in user and session system to control access to API endpoints. It fits best when an API serves a web-based interface that can follow Django’s redirect to a login page. section 11.2.5
Apply it with Django Ninja by:
- Importing django_auth from ninja.security. section 11.2.5
- Passing django_auth to the auth argument on an endpoint or the NinjaAPI class. section 11.2.5
- Choosing global, router-level, or endpoint-level protection. section 11.2.5
The important catch is the redirect: an unauthenticated API client must handle a web login form. That makes Django authentication suitable for browser-facing APIs, but awkward for APIs consumed directly by other systems. section 11.2.5
