A library that provides a simple Access Key & Secret Key authorization for Django REST framework.
Project description
DRF Access Key
A library that provides a simple Access Key & Secret Key authorization for Django REST framework.
Requirements
- Python 3.6+
- Django 2.X+
- Django REST framework 3.X+
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
- Add
rest_framework_access_key
toINSTALLED_APPS
setting:
INSTALLED_APPS = [
...,
'rest_framework_access_key',
]
- Add
AccessKeyAuthentication
toDEFAULT_AUTHENTICATION_CLASSES
setting located at settings.py from your project:
REST_FRAMEWORK = {
...,
'DEFAULT_AUTHENTICATION_CLASSES': (
...,
'rest_framework_access_key.authentication.AccessKeyAuthentication',
),
}
- 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
- Qi Zhao(zhaoqi99@outlook.com)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
drf-access-key-0.1.0.tar.gz
(18.9 kB
view hashes)
Built Distribution
Close
Hashes for drf_access_key-0.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 138daac5c6e3902394966ebe8d791cbfd96173b14a1d4e96698579c6f8f992fd |
|
MD5 | c67ba3eee3424be991ac6521e99fa3e4 |
|
BLAKE2b-256 | 7caba0e430a533102f0caa3c7a1b2e5715e788836eb8d0807de5d150e3a7063a |