Skip to main content

Wagtail-based authentication and authorization for the Early Detection Research Network

Project description

🔑 EDRN Auth

This is a Django app (that is, Python package) that provides authentication and authorization for the portal for the Early Detection Research Network and other applications. You use it with the Wagtail CMS.

It currently works with:

  • Wagtail versions less than 8 but greater than 5
  • Django versions less than 6 but greater than 4
  • Python versions 3.10 or greater (but probably less than 4)

💁 How to Use It

Simply add edrn.auth to your list of dependencies and install it (such as in requirements.txt or pyproject.toml's dependencies)), then add it your site's INSTALLED_APPS. Next you'll want to import edrn.auth's URL patterns with something like this in your own urls.py:

from edrn.auth.urls import urlpatterns as edrn_auth_urlpatterns

urlpatterns = edrn_auth_urlpatterns + [
    # your own URL patterns
]

This will give you several URL paths:

  • _util/login/ for logging in, overriding the Wagtail frontend login template, with the full U.S. government boilerplate and the three login alternatives (portal, LabCAS, DMCC "secure" site)
  • _util/portal-login (named portal_login), for logging in, with the full U.S. government boilerplate but only portal login (LabCAS and DMCC "secure" site are not mentioend)
  • logout/ (named logout), for logging out
  • authentication-test (named authentication-test), for testing if credentials are valid, using HTTP Basic

This gives a template tag library which you can use by first doing {% load edrn_auth_tags %}; it provides a single inclusion tag, edrn_personal_links, which generates the "personal links":

  • A "Hello, {{name}}" if you're logged in (or just "You're logged in" if your name's unknown), plus a "Log out" link
  • A "Log in" link if you're not logged in.

There are several utilities you can import from edrn.auth.views, which are described below.

🔐 view_or_basicauth

view_or_basicauth is used as a decorator on a view along with a test function, test_func. The test_func is expected to receive a single argument, the Django HTTPRequest.user.

If the test function succeeds, the decorated view is returned. Otherwise, if HTTP Basic authentication is present and succeeds, the decorated view is returned.

Otherwise, the HTTP "unauthorized" status is returned with an HTTP Basic challenge.

🔒 logged_in_or_basicauth

The decorator logged_in_or_basicauth just uses the above view with the test_func set to user.is_authenticated.

🔏authentication_context

The function authentication_context takes a Django HTTPRequest and based on its state, returns a dictionary with the following values:

  • authenticated: True if there's an authenticated user present, False otherwise
  • logout: The URL to visit to have the current user logout, if applicable
  • login: The URL to visit to present a full login page (with the three alternative destinations, portal, LabCAS, and DMCC "secure" site)
  • portal_login: The URL to visit to present the portal-only login page

This is intended to be used in get_context methods or views to provide handy links.

🪙 Changes

  • 2.2.1 actually works with Python 3.10 or newer
  • 2.2.0 requires Wagtail version to be > 5, < 8
  • 2.1.0 supports Python 3.13 or newer
  • 2.0.2 increased Wagtail support from < 6 to < 7
  • 2.0.1 increased Django support from < 5 to < 6

🥖 Translations

This package hasn't be translated into any other languages aside from US English.

👏 Contributing

All of the developers of this package are expected to abide by our Code of Conduct. Do check it out! We don't take this lightly and we have high standards of our community. For information on how to contribute software to the Early Detection Research Network, check out our contributor guidelines.

🎈 Support

If you're experiencing issues, view to see if an issue's been filed (or file a fresh one) at our issue tracker. Or you can reach us by email.

🪪 License

This package is licensed under the Apache License, version 2. See the LICENSE.md file for details.

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

edrn_auth-2.2.1.tar.gz (13.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

edrn_auth-2.2.1-py3-none-any.whl (21.9 kB view details)

Uploaded Python 3

File details

Details for the file edrn_auth-2.2.1.tar.gz.

File metadata

  • Download URL: edrn_auth-2.2.1.tar.gz
  • Upload date:
  • Size: 13.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for edrn_auth-2.2.1.tar.gz
Algorithm Hash digest
SHA256 21eee2d3e7c233dc62550fbb5e353f876c12210bf2ed3f15550cbe6e907061be
MD5 684a40bfb1d261a4408d636308314be8
BLAKE2b-256 46adfb6e041ed6d35965f1386f880432d9b6b62dce029bfb0b1c0ba879c307b6

See more details on using hashes here.

File details

Details for the file edrn_auth-2.2.1-py3-none-any.whl.

File metadata

  • Download URL: edrn_auth-2.2.1-py3-none-any.whl
  • Upload date:
  • Size: 21.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for edrn_auth-2.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 7473fd5b267fac1387ae735d8e8883a950104fad766493900393d1a7711cae8b
MD5 71b193e43633092459f8728b7e0888d1
BLAKE2b-256 0899845eddf6108cc8b97ad377cb5ffa31034998d236f0a33c42068ca2faffc0

See more details on using hashes here.

Supported by

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