/django-library

Primary LanguagePythonMIT LicenseMIT

django-esidoc

Python 3.10 Django 3.2 Python CI Code style: black
Handle CAS login via sso for french libraries (C3RB, GMInvent and Archimed).

Installation

Install with pip:

pip install -e git://github.com/briefmnews/django-library.git@main#egg=django-library

Setup

In order to make django-library works, you'll need to follow the steps below.

Settings

First you need to add the following configuration to your settings:

INSTALLED_APPS = (
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.sessions',
    'django.contrib.messages',

    'django_library',
    ...
)

MIDDLEWARE_CLASSES = (
    'django.middleware.common.CommonMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    
    'django_library.middleware.CASMiddleware',
    ...
)

AUTHENTICATION_BACKENDS = (
    'django.contrib.auth.backends.ModelBackend',
    
    'django_library.backends.CASBackend',
    ...
)

Migrations

Next, you need to run the migrations in order to update your database schema.

python manage.py migrate

Mandatory settings

Here is the list of all the mandatory settings:

LIBRARY_GMINVENT_BASE_URL
LIBRARY_C3RB_BASE_URL
LIBRARY_ARCHIMED_BASE_URL
LIBRARY_QUERY_STRING_TRIGGER

Optional settings - Default redirection

You can set a default path redirection for inactive user by adding this line to your settings:

LIBRARY_INACTIVE_USER_REDIRECT = '/{mycustompath}/'

LIBRARY_INACTIVE_USER_REDIRECT is used if an inactive user with a valid ticket tries to login. If LIBRARY_INACTIVE_USER_REDIRECT is not set in the settings, it will take the root path (i.e. /) as default value.

How to use ?

Once your all set up, when a request to your app is made with the query string library_sso_id=<unique_sso_id>, the CASMiddleware catches the request and start the login process. Here is an example of a request url to start the login process:

https://www.exemple.com/?library_sso_id=briefme

Tests

Testing is managed by pytest. Required package for testing can be installed with:

pip install -r test_requirements.txt

To run testing locally:

pytest

Credits

References