Django app for authentication via TUID (CAS)
Project description
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.
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pyTUID-1.3.5.tar.gz.
File metadata
- Download URL: pyTUID-1.3.5.tar.gz
- Upload date:
- Size: 8.4 kB
- Tags: Source
- Uploaded using 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
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
933940824817e2f5c38dc3e8f4218f15923d5747abe085aaff804e4980cda35e
|
|
| MD5 |
1491820ababde779310eb386d14d6846
|
|
| BLAKE2b-256 |
12ea83567cd29350405ad30a266db1ae489abf43c79e32df42b7e5e86732d9d0
|
File details
Details for the file pyTUID-1.3.5-py3-none-any.whl.
File metadata
- Download URL: pyTUID-1.3.5-py3-none-any.whl
- Upload date:
- Size: 12.4 kB
- Tags: Python 3
- Uploaded using 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
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
39b44854bbcbb58e8eb4e3b6b316d00e066918b448dd0e5b1b5825f289e22353
|
|
| MD5 |
b8f972b098d2f19791a8cc46d6e2b5b6
|
|
| BLAKE2b-256 |
ba9b3a4502b1acb73ab877246ac855a18ceb7212bd071e464aa310a5c163881e
|