Package: django-ucamwebauth
Introductiondjango-ucamwebauth is a library which provides use of Cambridge University'sRaven authenticationforDjango. It provides a Django
authentication backend which can be added toAUTHENTICATION_BACKENDSin the Djangosettingsmodule.UseInstall django-ucamwebauth using pip:pipinstalldjango-ucamwebauthThen you can enable it within your Django project's settings.py:AUTHENTICATION_BACKENDS=('ucamwebauth.backends.RavenAuthBackend','django.contrib.auth.backends.ModelBackend')This allows both normal Django login and Raven login.You should then enable the URLs for ucamwebauth:#Django 1.11urlpatterns=[...url(r'',include('ucamwebauth.urls')),...]#Django >=2.0urlpatterns=[...path(r'',include('ucamwebauth.urls')),...]Minimum Config SettingsYou then need to configure the app's settings. Raven has a live and test environments, the URL and certificate details
are given below.There are four minimum config settings:UCAMWEBAUTH_LOGIN_URL: a string representing the URL for the Raven login redirect.
UCAMWEBAUTH_LOGOUT_URL: a string representing the logout URL for Raven.
UCAMWEBAUTH_RETURN_URL: the URL of your app which the Raven service should return the user to after authentication.
    (Default is generated automatically from the urlconf)
UCAMWEBAUTH_LOGOUT_REDIRECT: a string representing the URL to where the user is redirected when she logs out of the app
    (Default to '/').
UCAMWEBAUTH_NOT_CURRENT: a boolean value representing if raven users that are currently not members of the university
    should be allowed to log in (Default to False). More info: http://www.ucs.cam.ac.uk/accounts/ravenleaving
UCAMWEBAUTH_CERTS: a dictionary including key names and their associated certificates which can be downloaded from the
    Raven project pages.
UCAMWEBAUTH_TIMEOUT: An integer with the time (in seconds) that has to pass to consider an authentication timed out
    (Default to 30).
UCAMWEBAUTH_REDIRECT_AFTER_LOGIN: The url where you want to redirect the user after login (Default to '/').
UCAMWEBAUTH_CREATE_USER: This defaults to True, allowing the autocreation of users who have been successfully 
authenticated by Raven, but do not exist in the local database. The user is created with set_unusable_password().An example, referencing the Raven test environment is given below:UCAMWEBAUTH_LOGIN_URL='https://test.legacy.raven.cam.ac.uk/auth/authenticate.html'UCAMWEBAUTH_LOGOUT_URL='https://test.legacy.raven.cam.ac.uk/auth/logout.html'UCAMWEBA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CAzZNFqCentiHO08LfX/tr7+q6DaMuIh8RQpOfowDsIhaiB2YtK1A+B6dJxnHAq+a6sX7ZBwtZoWyBtUalrNMyGGN4eaEuRUIL9ilCksI7Nb4X91dyryO/L/QI4XQtbaz7j8K8hSJJ4MGb6Boc1Ov69ZEkGY322DIS84WfeSem6Ujy4TyZSkmUPOiiT9bFN2MUomKJAgMBAAEwDQYJKoZIhvcNAQELBQADggEBAGg+4IDXLtypkoxteb8KQWvt11d4xMljNmJ6k20gBpPEd5nzocQ7MeSv9l66NrlsHCJ+BwJjJDgIS4dwkofu+hmkLNE6/d3uHugKazv3ySw+g5oIcLNBvjgIhbD4krVSh4LvZxQR+sffQnrkzSSAB6/6QMTtAcor61A+0Xo4OhvPHMWOcS9IrT57/9Slr9eEtSUcpKs+cyY9G6t9GxdC627diApsw+mG2X1raFIROXuXMzQQysEI6SzxRFof2AutEgcyYRERLbHIqH5K1EgjLWs3s4PujOhTvhUoJZ7OlTjNmzNrFXKj9nU4Uo6qClXDVKK7JecERsAfIedKgFGbQqY=-----END CERTIFICATE-----"""}ErrorsThere are five possible exceptions that can be raised using this module: MalformedResponseError, InvalidResponseError,
PublicKeyNotFoundError, and OtherStatusCode that return HTTP 500, or UserNotAuthorised that returns 403. You can catch
these exceptions using process_exception middleware
(https://docs.djangoproject.com/en/2.2/topics/http/middleware/#process_exception) to customize what the user will
receive as a response. The module has a default behaviour for these exceptions with HTTP error codes and using their
corresponding templates. To use the default behaviour just add:MIDDLEWARE=[...'ucamwebauth.middleware.DefaultErrorBehaviour',...]INSTALLED_APPS=[...'ucamwebauth',...]You can also rewrite the ucamwebauth_<httpcode>.html templates. You only need to add the following lines to your own if
you want to show the user the error message:{%formessageinmessages%}{{message}}<br/>{%endfor%}Authentication request parametersThis parameters are sent with the authentication request and allows the developer to tune the request to fit their app:UCAMWEBAUTH_DESC: A text description of the resource requesting authentication which may be displayed to the end-user
    to further identify the resource to which his/her identity is being disclosed. Can be omitted.
UCAMWEBAUTH_IACT: The value 'yes' requires that a re-authentication exchange takes place with the user. This could be
    used prior to a sensitive transaction in an attempt to ensure that a previously authenticated user is still present
    at the browser. The value 'no' requires that the authentication request will only succeed if the user's identity
    can be returned without interacting with the user. This could be used as an optimisation to take advantage of any
    existing authentication but without actively soliciting one. If omitted or empty, then a previously established
    identity may be returned if the WLS supports doing so, and if not then the user will be prompted as necessary.
UCAMWEBAUTH_MSG: Text describing why authentication is being requested on this occasion which may be displayed to the
    end-user. Can be omitted.
UCAMWEBAUTH_PARAMS: Data that will be returned unaltered to the WAA in any 'authentication response message' issued as
    a result of this request. This could be used to carry the identity of the resource originally requested or other
    WAA state, or to associate authentication requests with their eventual replies. When returned, this data will be
    protected by the digital signature applied to the authentication response message but nothing else is done to
    ensure the integrity or confidentiality of this data - the WAA MUST take responsibility for this if necessary.
UCAMWEBAUTH_FAIL: If this parameter is 'yes' and the outcome of the request is anything other than success (i.e. the
    status code would be anything other than 200) then the WLS MUST return an informative error to the user and MUST
    not redirect back to the WAA. Setting this makes it easier to implement WAAs at the expense of a loss of
    flexibility in error handling.The details of these can be found in the Raven WLS protocol documentation,here.