Skip to content

A library that provides a simple Access Key & Secret Key authorization for Django REST framework.

License

Notifications You must be signed in to change notification settings

ZhaoQi99/drf-access-key

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

DRF Access Key

Python version PyPI - Versions from Framework Classifiers PyPI package PyPI download GitHub GitHub last commit (by committer)

A library that provides a simple Access Key & Secret Key authorization for Django REST framework.

Requirements

Install

pip install drf-access-key
✨🍰✨

Or you can use pip install git+https://github.com/ZhaoQi99/drf-access-key.git install latest version.

Quick Start

  1. Add rest_framework_access_key to INSTALLED_APPS setting:
INSTALLED_APPS = [
    ...,
    'rest_framework_access_key',
]
  1. Add AccessKeyAuthentication to DEFAULT_AUTHENTICATION_CLASSES setting located at settings.py from your project:
REST_FRAMEWORK = {
    ...,
    'DEFAULT_AUTHENTICATION_CLASSES': (
        ...,
      	'rest_framework_access_key.authentication.AccessKeyAuthentication',
    ),
}
  1. Custom authentication_classes in Django REST framework APIView:
from rest_framework import generics,permissions
from rest_framework.response import Response

from rest_framework_access_key.authentication import AccessKeyAuthentication

class TestViewSet(generics.GenericAPIView):
    authentication_classes = (AccessKeyAuthentication,)
    permission_classes = (permissions.IsAuthenticated,)

    def get(self, request, *args, **kwargs):
        return Response({"Hello": "World!"})

How to use

Authentication Method Document 🇨🇳

GET /api/v1/user/ HTTP/1.1
Auth-Access-Key: XXXXXXXX
Auth-Nonce: 83a1ca5507564efd891ad8d6e04529ee
Auth-Timestamp: 1677636324
Content-Type: application/json
Auth-Signature: XXXXXXX

Settings

Settings are configurable in settings.py in the scope ACCESS_KEY_SETTINGS. You can override any setting, otherwise the defaults below are used.

ACCESS_KEY_DEFAULTS: Dict[str, Any] = {
    "NONCE_CACHE_PREFIX": "OpenAPI",
    "NONCE_CACHE_TTL": 5,
    "TIMESTAMP_ERROR_RANGE": 10 * 60,
}

License

GNU General Public License v3.0

Author

About

A library that provides a simple Access Key & Secret Key authorization for Django REST framework.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages