Skip to main content

Easy to use API key authentication for Django Ninja REST Framework

Project description

Django Ninja APIKey - Easy to use API key authentication for Django Ninja REST Framework

This is an unofficial Django app which makes it easy to manage API keys for the Django Ninja REST Framework.

Key Features:

  • Easy integration in your projects
  • Well integrated in the admin interface
  • Secure API keys due to hashing
  • Works with the standard user model

Installation

pip install django-ninja-apikey

Usage

Add ninja_apikey to your installed apps in your django project:

# settings.py

INSTALLED_APPS = [
    # ...
    "ninja_apikey",
]

Run the included migrations:

python manage.py migrate

Secure an api endpoint with the API keys:

# api.py

from ninja import NinjaAPI
from ninja_apikey.security import APIKeyAuth

#  ...

auth = APIKeyAuth()
api = NinjaAPI()

# ...

@api.get("/secure_endpoint", auth=auth)
def secure_endpoint(request):
    return f"Hello, {request.user}!" 

Or secure your whole api (or a specific router) with the API keys:

# api.py

from ninja import NinjaAPI
from ninja_apikey.security import APIKeyAuth

#  ...

api = NinjaAPI(auth=APIKeyAuth())

# ...

@api.get("/secure_endpoint")
def secure_endpoint(request):
    return f"Hello, {request.user}!" 

You can create now API keys from django's admin interface.

What next?

  • To support this project, please give a star on GitHub.
  • For any kind of issue feel free to open an Issue.
  • Contributors are welcome! Please refer to CONTRIBUTING.md.

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-apikey-0.1.0.tar.gz (5.7 kB view hashes)

Uploaded Source

Built Distribution

django_ninja_apikey-0.1.0-py3-none-any.whl (7.0 kB view hashes)

Uploaded Python 3

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