No project description provided
Project description
Django Hawk
A descriptive line about the package
Installation
pip install django-hawk
Add the following to your Django Settings:
DJANGO_HAWK = {
"HAWK_INCOMING_ACCESS_KEY": "xxx",
"HAWK_INCOMING_SECRET_KEY": "xxx",
}
Example Usage
To use the HAWK Authentication, we need to do 2 things:
- Make sure the
HawkResponseMiddleware
runs - Check the authentication
If you want all of your views to be authenticated with HAWK, then you can add the HawkResponseMiddleware
to the MIDDLEWARE
setting in your project like so:
MIDDLEWARE = [
...
"django_hawk.middleware.HawkResponseMiddleware",
...
]
Alternatively, if you only want some of your views to be protected with HAWK, you can add the HawkResponseMiddleware
using the decorator_from_middleware
method.
To check the authentication you can call django_hawk.utils.authenticate_request
, if an exception isn't raised then you know that the request is authenticated, see below for examples.
from django.http import HttpResponse
from django.utils.decorators import decorator_from_middleware
from django_hawk.middleware import HawkResponseMiddleware
from django_hawk.utils import DjangoHawkAuthenticationFailed, authenticate_request
# Decorate with the middleware
@decorator_from_middleware(HawkResponseMiddleware)
def simple_view(request):
# Try to authenticate with HAWK
try:
authenticate_request(request=request)
except DjangoHawkAuthenticationFailed as e:
return HttpResponse(status=401)
# Continue with normal View code...
return HttpResponse("This is a simple view")
Testing
Tests belong in the /django_hawk/tests/
directory. You can run the tests by installing the requirements like so:
pip install -r dev-requirements.txt
Now you can run the tests using the following command:
./manage.py test
Tox tests
We use tox to test compatibility across different Django versions.
To run these tests with tox, just run the following:
tox
Pushing to PyPI
Running make build
will build the package into the dist/
directory
Running make push-pypi-test
will push the built package to Test PyPI
Running make push-pypi
will push the built package to PyPI
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for django_hawk-0.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2f2e182dd663448205f6ab8df14b98ebb4d2df3d86d8e1503071091c8c6845cb |
|
MD5 | 5445d9fe55fd3cb7331a6cc3addd4ec2 |
|
BLAKE2b-256 | 9a6dff4fbc2ac0872d70aeb3d727fb51a39f7dda0041932c901c595ff1531fa3 |