Skip to main content

Django Hawk

This package can be used to help create HAWK Authenticated views.

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:

  1. Make sure the HawkResponseMiddleware runs
  2. Check the authentication

Add the HawkResponseMiddleware to the MIDDLEWARE setting in your project like so:

MIDDLEWARE = [
    ...
    "django_hawk.middleware.HawkResponseMiddleware",
    ...
]

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_hawk.utils import DjangoHawkAuthenticationFailed, authenticate_request

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:

make setup

Now you can run the tests using the following command:

poetry run python 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:

make tox

Pushing to PyPI

Running make build-package 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.

Setting up poetry for pushing to PyPI

First you will need to add the test pypy repository to your poetry config:

poetry config repositories.test-pypi https://test.pypi.org/legacy/

Then go to https://test.pypi.org/manage/account/token/ and generate a token.

Then add it to your poetry config:

poetry config pypi-token.test-pypi XXXXXXXX

Then you also need to go to https://pypi.org/manage/account/token/ to generate a token for the real PyPI.

Then add it to your poetry config:

poetry config pypi-token.pypi XXXXXXXX

Now the make commands should work as expected.

Metadata

Release files for django-hawk 1.2.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-hawk 1.2.5
File Size Uploaded
django_hawk-1.2.5.tar.gz 7.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for django-hawk 1.2.5
File Interpreter ABI Platform
django_hawk-1.2.5-py3-none-any.whl Python 3 none any Details

Total release size: 16.7 kB

Release files / django_hawk-1.2.5.tar.gz

Download URL django_hawk-1.2.5.tar.gz
Size 7.1 kB
Tags Source
SHA-256 checksum
How to use checksums
d7bd479590a6fb5ea5fb2c4b13bbff14708c9a10a1aa4e7b05bd9f27cfed3e64
BLAKE2b-256 checksum
How to use checksums
8b1c5e20dbcaee3d3d3ecafbc17c264b8d2a2dd6d0f8df1f9999344649f0d079
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.3 CPython/3.12.4 Darwin/24.5.0

Release files / django_hawk-1.2.5-py3-none-any.whl

Download URL django_hawk-1.2.5-py3-none-any.whl
Size 9.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a491d318db150d0f24a41d3730f8f1c792255dd99912565de8d83491c5156b93
BLAKE2b-256 checksum
How to use checksums
bf1e6cf6f2bfd5f526535234ed6879fc38225259664eeb4a7a766288c55a54f2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.3 CPython/3.12.4 Darwin/24.5.0

Release history Release notifications | RSS feed

This release

1.2.5 This release

2 release files

1.2.4

2 release files

1.2.3

2 release files

1.2.2

2 release files

1.2.1

2 release files

1.2.0

2 release files

1.1.1

2 release files

1.1.0

2 release files

1.0.0

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page