-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #535 from DH-IT-Portal-Development/acceptation
Acceptation to develop[
- Loading branch information
Showing
13 changed files
with
372 additions
and
107 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
"""Copy this file to saml_settings.py if you want to use local SAML | ||
This will 1) enable SAML in settings.py and 2) configure the SAML library to | ||
use your local Development IdP. | ||
For more information on the DevIdP, please consult its Github page: | ||
https://github.com/CentreForDigitalHumanities/Development-IdP | ||
You'll also need some certs, this code assumes they are located in a 'certs' | ||
dir at the project-root. These certs can either be borrowed from the Dev-IdP | ||
project or generated by hand. For the latter, see the CDH Docs. | ||
These certs are used for signing the SAML data from this app to the IdP. | ||
For detailed documentation on SAML and the CDH Federated Auth library, please | ||
consult the CDH Federated Authentication docs: | ||
https://centrefordigitalhumanities.github.io/Federated-Authentication-Docs/ | ||
""" | ||
import os | ||
|
||
# Import all default SAML settings from the library, we override some later | ||
# Tip: the imported file also contains a lot of docs, which might be nice to | ||
# read also | ||
from cdh.federated_auth.saml.settings import * | ||
|
||
# Used to get the full path of <project_root> | ||
_BASE_DIR = os.path.dirname(os.path.dirname(__file__)) | ||
|
||
# This dict is used to map attributes send by the IdP to the attributes used | ||
# in this app's user model. They key is the name of the attribute as sent by | ||
# the IdP, the value is a tuple with the name of the field on the user model | ||
# See also: | ||
# https://djangosaml2.readthedocs.io/contents/setup.html#users-attributes-and-account-linking | ||
SAML_ATTRIBUTE_MAPPING = { | ||
'uuShortID': ('username',), | ||
'mail': ('email',), | ||
'givenName': ('first_name',), | ||
'uuPrefixedSn': ('last_name',), | ||
# TODO: create an attribute on the user model to store this value | ||
# 'uuLegacyDepartment': (), | ||
} | ||
|
||
# Controls which mechanism is used to exchange SAML data with the IdP | ||
# Either POST or REDIRECT. POST is generally preferred, as REDIRECT can run | ||
# into problems as it encodes the SAML data into the URL. | ||
SAML_DEFAULT_BINDING = saml2.BINDING_HTTP_POST | ||
|
||
# Use the helper function to generate the SAML_CONFIG. | ||
# This is the main setting used to set up SAML | ||
SAML_CONFIG = create_saml_config( | ||
# This should be the URL of the ethics app (with protocol). Currently | ||
# localhost, port 8000. Please change if you run the app on a different | ||
# hostname/port | ||
# Note that localhost and 127.0.0.1 are not interchangeable here | ||
base_url='http://localhost:8000/', | ||
# The name of the app, does not _really_ matter | ||
name='FEtC-H Portal', | ||
# The full location of the private key of the cert, currently | ||
# <project_root>/certs/private.key | ||
key_file=os.path.join(_BASE_DIR, 'certs/private.key'), | ||
# The full location of the certificate, currently | ||
# <project_root>/certs/private.key | ||
cert_file=os.path.join(_BASE_DIR, 'certs/public.cert'), | ||
# The location of the IdP's metadata | ||
# The current value is valid for the Development IdP, if run at port 7000 | ||
# If you run it in a different place/port, please update | ||
# If you use a different IdP, find its metadata URL and copy/paste it here | ||
idp_metadata='http://localhost:7000/saml/idp/metadata/', | ||
# If set to True, the app will allow login attempts not requested by the app | ||
# This _can_ happen if a user logs in directly from the IdP. Currently set | ||
# to true, as the DevIdP can sometimes do funky stuff with the session ID | ||
allow_unsolicited=True, | ||
# A list of attributes the IdP needs to provide for the app to authenticate | ||
# Uses the naming of the IdP, not the internal names in Django | ||
required_attributes=['uuShortID', 'mail', 'givenName', 'uuPrefixedSn'], | ||
# A list of nice-to-have attributes from the IdP | ||
# Uses the naming of the IdP, not the internal names in Django | ||
optional_attributes=['uuLegacyDepartment', ], | ||
# Contact info for this app; will be added to the app's metadata and is | ||
# generally used by the IdP admins to contact all app-admins if they change | ||
# something. | ||
contact_given_name='Humanities IT Portal Development', | ||
contact_email='[email protected]', | ||
) | ||
|
||
# Add the SAML auth backend to the list of enabled backends. | ||
AUTHENTICATION_BACKENDS = ( | ||
'django.contrib.auth.backends.ModelBackend', | ||
'djangosaml2.backends.Saml2Backend', | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.