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 6 but greater than 5
- Django versions less than 6 but greater than 4
- Python versions 3.11 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
(namedportal_login
), for logging in, with the full U.S. government boilerplate but only portal login (LabCAS and DMCC "secure" site are not mentioend)logout/
(namedlogout
), for logging outauthentication-test
(namedauthentication-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
otherwiselogout
: The URL to visit to have the current user logout, if applicablelogin
: 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.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
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
Built Distribution
File details
Details for the file edrn_auth-2.0.1.tar.gz
.
File metadata
- Download URL: edrn_auth-2.0.1.tar.gz
- Upload date:
- Size: 13.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.11.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 790dac7f2df97cc0986117dc4a0e7b98726099d308a08ba7e9da06400ba8171d |
|
MD5 | a80d6183e9ee2d9a994e7c7a05698443 |
|
BLAKE2b-256 | c4709c76cda66acb7738bbc697fbd8e71a4298a4793ac3d1744d7f2a4b9325fa |
File details
Details for the file edrn_auth-2.0.1-py3-none-any.whl
.
File metadata
- Download URL: edrn_auth-2.0.1-py3-none-any.whl
- Upload date:
- Size: 22.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.11.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3e17e3f77d0ccaa233aef2c4d2df1795249e3ccc52bc512edbe2d65e560ff077 |
|
MD5 | 098541829624da247aa9d5ad6c66ba68 |
|
BLAKE2b-256 | 525879e77749b12a587fe1a6286350d17b78deef2438fe0e90dbc17fb2fe670a |