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.

License

This project is licensed under the terms of the MIT license.

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

Uploaded Source

Built Distribution

django_ninja_apikey-0.2.1-py2.py3-none-any.whl (7.5 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file django-ninja-apikey-0.2.1.tar.gz.

File metadata

  • Download URL: django-ninja-apikey-0.2.1.tar.gz
  • Upload date:
  • Size: 10.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.26.0

File hashes

Hashes for django-ninja-apikey-0.2.1.tar.gz
Algorithm Hash digest
SHA256 c7559a52b55ab9cc62005248cf55989e9509d47a0f7d1800d9d7257f64e01c54
MD5 9cb51dba52b390bb6d8b8c2c4ec4a956
BLAKE2b-256 7dc1231060988ee43426684e0ea03b4ccc2c15271d719cea7879e6a6ac43627f

See more details on using hashes here.

File details

Details for the file django_ninja_apikey-0.2.1-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for django_ninja_apikey-0.2.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 7abc22ec871467d80c8f37e311b5f968f4f489258182c302451b2420593c3bb4
MD5 afe456d1e16d9098f05760c7879a385d
BLAKE2b-256 03f0962918a8bf77f1cec5ce148178be9b3eecd1da128b031a7a34f52f0223dd

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