Skip to content
master
Go to file
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
 
 

README.md

django-rest-apikey

Add a per-user API key to authenticate in Django REST Framework

Installation

Install using pip:

pip install django_rest_apikey

Add 'django_rest_apikey' to INSTALLED_APPS:

INSTALLED_APPS = (
    ...
    'django_rest_apikey',
)

And add the authentication class:

REST_FRAMEWORK = {
    'DEFAULT_AUTHENTICATION_CLASSES': (
        ...
        'django_rest_apikey.authentication.APIKeyAuthentication',
    ),
    ...
}

Additionally, you can add this to your router to allow users to manage there API keys:

from django_rest_apikey.views import APIKeyViewSet
...
your_router.register(r'apikeys', APIKeyViewSet, base_name='apikeys')

Also, don't forget to create the new model in the database:

python manage.py migrate

Usage

The API-Key header is looked by the class to authenticate the user.

response = requests.get(
    url="http://0.0.0.0:8000/api/your_model",
    headers={
        "Api-Key": "fd8b4a98c8f53035aeab410258430e2d86079c93",
    },
)

About

Per-user API key to authenticate in Django REST Framework

Resources

Releases

No releases published

Languages

You can’t perform that action at this time.