drf-simple-apikey offers a robust solution for API Key authentication with built-in rotation features. Utilizing the fernet encryption module, it ensures fast and secure transactions while keeping API credentials safe. Ideal for developers seeking a seamless integration with Django, this package enhances the security of REST APIs effortlessly.
Django REST Framework Simple API Key is a streamlined and secure solution for API Key authentication utilizing the Django REST Framework. This package offers the ability to quickly generate, encrypt, and manage API keys, enhancing security while maintaining performance.
Key Features
-
Fast Performance: Utilizing the Fernet cryptography module, the package ensures rapid API key operations including generation, encryption, and decryption.
-
Robust Security: Fernet encryption guarantees that data remains secure, preventing unauthorized access and tampering. The
FERNET_KEY
is essential and should be kept secure, similar to the DjangoSECRET_KEY
setting. -
Customization Options: The package allows for extensive customization of models, authentication backends, and permission classes, ensuring alignment with specific project requirements. The API key settings are conveniently stored in a singular configuration dictionary named
DRF_API_KEY
within thesettings.py
file.
Quick Integration
To get started, install the package with pip and register it in the Django settings:
pip install drf-simple-apikey
# settings.py
INSTALLED_APPS = [
# ...
"rest_framework",
"drf_simple_apikey",
]
Define the FERNET_KEY
in your settings, crucial for the authentication process:
DRF_API_KEY = {
"FERNET_SECRET": "sVjomf7FFy351xRxDeJWFJAZaE2tG3MTuUv92TLFfOA="
}
Then proceed with migrations and incorporate the authentication into your views:
python manage.py migrate
from rest_framework import viewsets
from drf_simple_apikey.backends import APIKeyAuthentication
from rest_framework.response import Response
class FruitViewSets(viewsets.ViewSet):
http_method_names = ["get"]
authentication_classes = (APIKeyAuthentication,)
def list(self, request):
return Response([{"detail": True}], 200)
API Key Rotation
This package supports API key rotation strategies to further enhance security; detailed information can be found in the documentation.
Demo and Contribution
For demonstration purposes, check the example
directory in the repository and learn how to set up a development environment for contributions following the guidelines provided in the CONTRIBUTING.md.
Documentation
Comprehensive documentation is available at Django REST Framework Simple API Key Documentation. This resource covers all aspects of installation, configuration, and usage.
No comments yet.
Sign in to be the first to comment.