Skip to main content

Authenticate to Django with JSON Web Tokens (JWTs) signed by Cloudflare Access

Project description

Authenticate to Django with JSON Web Tokens (JWTs) signed by Cloudflare Access. A Django reimplementation of https://developers.cloudflare.com/cloudflare-one/identity/authorization-cookie/validating-json/#python-example

To run the demo, set the following environment variables:

export ALLOWEDFLARE_ACCESS_URL=https://your-organization.cloudflareaccess.com
export ALLOWEDFLARE_AUDIENCE=64-character hexidecimal string
export ALLOWEDFLARE_PRIVATE_DOMAIN=your-domain.tld

Then run

docker compose up

Configure Cloudflare Tunnel public hostname demodj.your-domain.tld to http://localhost:8001 or equivalent.

TODO

  • Iterate on the same-origin (re-)authenticating proxy
  • Iterate on Admin site ModelBackend
    • http://localhost:8001/admin/login/ text when authenticated is "You are authenticated as , but are not authorized to access this page. Would you like to login to a different account?"
  • Expand unit test coverage
  • Basic integration and end-to-end tests
  • mTLS support and testing
  • Configure PostgreSQL
    • Post-migration hook to create a readonly DB user
    • Use the readonly DB user for django-sql-explorer and jupyterhub
    • Update the django-sql-explorer allowlist to accept SET since it's only dangerous for MySQL
    • Exclude only specific fields, like password hash, from the django-sql-explorer view of the django.contrib.auth schema
    • See if admin site change history fields can be shown in the django-sql-explorer schema viewer

Open Questions

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

allowedflare-2024.28.2.tar.gz (8.6 kB view details)

Uploaded Source

Built Distribution

allowedflare-2024.28.2-py3-none-any.whl (8.9 kB view details)

Uploaded Python 3

File details

Details for the file allowedflare-2024.28.2.tar.gz.

File metadata

  • Download URL: allowedflare-2024.28.2.tar.gz
  • Upload date:
  • Size: 8.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.12.3

File hashes

Hashes for allowedflare-2024.28.2.tar.gz
Algorithm Hash digest
SHA256 fa6e6e7d8f2cc8b5de951482a3ae0dded8653adcfc334e7c045f4ed9a7b7d4a0
MD5 7ab17c2df941370eb6bb3b5cb62703cf
BLAKE2b-256 c3ce38ff2474d567128243b07d5b1a36121b1ea2c42fa354436e441730d7bdf8

See more details on using hashes here.

File details

Details for the file allowedflare-2024.28.2-py3-none-any.whl.

File metadata

File hashes

Hashes for allowedflare-2024.28.2-py3-none-any.whl
Algorithm Hash digest
SHA256 4ca878cddcdc634edccba35a7b70f850d1ca6033b52f499ea34495ff11002ddf
MD5 633193f8264aead8141e8ebf7d6af1ab
BLAKE2b-256 9f943bad62f526a9ebefddc00f8cd41fe8edfa6e3b793666232570b515309029

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page