Package: djangorestframework-simple-apikey
Django REST Framework Simple API Key 🔐Django REST Framework Simple API Key is a fast and secure API Key authentication plugin for REST API built withDjango Rest Framework.For the full documentation, visithttps://djangorestframework-simple-apikey.readthedocs.io/en/latest/.IntroductionDjango REST Simple Api Key is a package built upon Django, Django REST Framework, and the fernet cryptography module to generate, encrypt, and decrypt API keys. It provides fast, secure and customizable API Key authentication.BenefitsWhy should you use this package for your API Key authentication?⚡️Fast: We use thefernetcryptography module to generate, encrypt, and decrypt API keys. Besides the security facade, it is blazing fast allowing you to treat requests quickly and easily.🔐Secure: Fernet guarantees that a message encrypted using it cannot be manipulated or read without the key, which we callFERNET_KEY. As long as you treat the fernet key at the same level you treat the DjangoSECRET_KEYsetting, you are good to go.🔧Customizable: The models, authentication backend, and permissions classes can be rewritten and fit your needs. We do our best to extend Django classes and methods, so you can easily extend our classes and methods.😉 Your Api Key authentication settings are kept in a single configuration dictionary namedSIMPLE_API_KEYin thesettings.pyfile of your Django project. It can be customized to fit your project needs.Quickstart1 - Install withpip:pipinstalldjangorestframework-simple-apikey2 - Register the app in theINSTALLED_APPSin thesettings.pyfile:# settings.pyINSTALLED_APPS=[# ..."rest_framework","rest_framework_simple_api_key",]3- Add theFERNET_KEYsetting in yourSIMPLE_API_KEYconfiguration dictionary. You can easily generate a fernet key using thepython manage.py generate_fernet_keycommand. Keep in mind that the fernet key plays a huge role in the api key authentication system.SIMPLE_API_KEY={"FERNET_SECRET":"sVjomf7FFy351xRxDeJWFJAZaE2tG3MTuUv92TLFfOA="}4 - Run migrations:pythonmanage.pymigrateIn your view then, you can add the authentication class and the permission class.⚠️Important Note: By default, authentication is performed using theAUTH_USER_MODELspecified in the settings.py file.fromrest_frameworkimportviewsetsfromrest_framework_simple_api_key.backendsimportAPIKeyAuthenticationfromrest_framework.responseimportResponseclassFruitViewSets(viewsets.ViewSet):http_method_names=["get"]authentication_classes=(APIKeyAuthentication,)deflist(self,request):returnResponse([{"detail":True}],200)Generate a Fernet KeyWe've made it easier for you by creating a custom Django command to quickly generate a fernet key, which is acrucial componentin the authentication system. Make sure to keep the key secure and store it somewhere safely (ie: environment variable).Important ⛔️: You should treat theFERNET_KEYsecurity at the same level as the DjangoSECRET_KEY. 🫡To generate the fernet key use the following command:pythonmanage.pygenerate_fernet_keyRotationWe implement an API key rotation strategy for this package. To learn more about it, refer to the documentation athttps://djangorestframework-simple-apikey.readthedocs.io/en/latest/rotation.html.DemoYou can find a demo in project in theexampledirectory. To run the project, you can :cdexample
pipinstall-rrequirements.txt

pythonmanage.pymigrate
pythonmanage.pyrunserverChangelogSeeCHANGELOG.md.ContributingThank you for your interest in contributing to the project! Here's a guide to help you get started:Setup Development Environment:gitclonehttps://github.com/koladev32/djangorestframework-simple-apikey.gitUse the command below to set up your environment:make installFormat the Code:Before submitting any code, please ensure it is formatted according to our standards:make formatCheck Code and Migrations:Validate your changes against our checks:make checkRun Migrations:If your changes include database migrations, run the following:make migrationsRun Tests:Always make sure your changes pass all our tests:make testSeeCONTRIBUTING.md.