pyTUID
pyTUID is a simple CAS client django app which, contrary to other apps like this, don't use the django.contrib.auth models nor middleware. So all data is saved to a own database table (or not att all).
pyTUID is fitted for our use case with the CAS of the TU Darmstadt (hence the name) but can probably be used with many other CAS servers with a similar configuration (CAS 2 with SAML 1).
Feel free to adapt this app to your needs. If you make changes compatible to the current behavior (or if it is configurable) I would be glad if you made a pull request.
Setup
- To set up install this python library (for example with pip).
- In your
settings.py:- Add
pyTUIDto yourINSTALLED_APPS. - Add
pyTUID.middleware.TUIDMiddlewareto yourMIDDLEWARE_CLASSES. - Set at least
TUID_SERVER_URLto your CAS server URL.
- Add
- Include
pyTUID.urlsin yoururls.pyat any path you like. - Apply the migrations.
- That's it!
Configuration
Currently the following settings are available:
-
TUID_SERVER_URLthe CAS server URL (default:None) -
TUID_CREATE_USERsets whether the logged in users should be saved to the database (default:True) -
TUID_LOGIN_DEFAULT_NEXTsets the default page after login when nonextis present inPOSTorGETparameters (default:"/") -
TUID_LOGOUT_DEFAULT_NEXTsets the default page after logout when nonextis present inPOSTorGETparameters (default:"/") -
TUID_MAPPINGsets the mapping from SAML attributes to model fields (key is model field, value is SAML attribute) The default is:{'surname' : 'surname', 'given_name' : 'givenName', 'email' : 'mail', 'groups' : 'groupMembership'}
Every key not provided in your config will be set to default.
-
TUID_FORCE_SERVICE_URLsets the service url provided to CAS. If not set the request url is used as service url.
Usage
There are three different ways to use this app:
Decorators
For function based views the easiest interaction with this app is using the view function decorators:
tuid_login_required
The @tuid_login_required decorator checks whether the user is logged in (with TUID) and redirects it to the login page otherwise.
tuid_user_in_group
The @tuid_user_in_group(group[, permission_denied_message]) decorator first checks whether the user is logged in (with TUID) and displays the login page otherwise. If the user is already logged in it is checked whether it is in the given group and a PermissionDenied is risen with the optional permission_denied_message.
tuid_user_passes_test
The @tuid_user_passes_test(test_func[, raise_exception[, permission_denied_message]]) decorator applies the test_func on the TUIDUser object. If True is returned the view will be displayed as usual. If False is returned and raise_exception is True a PermissionDeniedexception with the optional permission_denied_message will be risen. If raisle_exceptio is False (the default) the login page will be displayed.
Mixins
For class based views the following two mixins exists:
TUIDLoginRequiredMixin
The TUIDLoginRequiredMixin works exactly like the tuid_login_required decorator.
TUIDUserInGroupMixin
The TUIDUserInGroupMixin works like the tuid_user_in_group decorator except that the parameters have to be specified as fields of the view class. The group_required field acts like the group parameter of the decorator and the permission_denied_message (optional) acts also like the permission_denied_messageof the decorator.
TUIDUser
For more specific use-cases you may use the TUIDUser object of the request, which is an instance of models.TUIDUSER.
Metadata
Release files for pyTUID 1.3.5
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| pyTUID-1.3.5.tar.gz | 8.4 kB | Without provenance | Details for pyTUID-1.3.5.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pyTUID-1.3.5-py3-none-any.whl | Python 3 | none | any | Details for pyTUID-1.3.5-py3-none-any.whl |
Total release size: 20.8 kB
Release files / pyTUID-1.3.5.tar.gz
| Download URL | pyTUID-1.3.5.tar.gz |
|---|---|
| Size | 8.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
933940824817e2f5c38dc3e8f4218f15923d5747abe085aaff804e4980cda35e
|
|
BLAKE2b-256 checksum How to use checksums |
12ea83567cd29350405ad30a266db1ae489abf43c79e32df42b7e5e86732d9d0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/44.0.0 requests-toolbelt/0.9.1 tqdm/4.41.1 CPython/3.6.7
|
Release files / pyTUID-1.3.5-py3-none-any.whl
| Download URL | pyTUID-1.3.5-py3-none-any.whl |
|---|---|
| Size | 12.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
39b44854bbcbb58e8eb4e3b6b316d00e066918b448dd0e5b1b5825f289e22353
|
|
BLAKE2b-256 checksum How to use checksums |
ba9b3a4502b1acb73ab877246ac855a18ceb7212bd071e464aa310a5c163881e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/44.0.0 requests-toolbelt/0.9.1 tqdm/4.41.1 CPython/3.6.7
|
Security for pyTUID 1.3.5
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.