Handle CAS login via sso for e-sidoc.
Install with pip:
pip install -e git://github.com/briefmnews/django-esidoc.git@master#egg=django_esidoc
In order to make django-esidoc
works, you'll need to follow the steps below.
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_esidoc',
...
)
MIDDLEWARE_CLASSES = (
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django_esidoc.middleware.CASMiddleware',
...
)
AUTHENTICATION_BACKENDS = (
'django.contrib.auth.backends.ModelBackend',
'django_esidoc.backends.CASBackend',
...
)
Then you need to add the logout
url to your urls.py
urlpatterns = [
...,
url(r'^esidoc/', include('django_esidoc.urls')),
...
]
To logout an user, with the example above, you need to call esidoc/logout/
.
You could call django_esidoc_logout
as well.
Next, you need to run the migrations in order to update your database schema.
python manage.py migrate
Here is the list of all the mandatory settings:
ENT_ESIDOC_BASE_URL
ESIDOC_QUERY_STRING_TRIGGER
You can set a default path redirection for inactive user by adding this line to your settings:
ESIDOC_INACTIVE_USER_REDIRECT = '/{mycustompath}/'
ESIDOC_INACTIVE_USER_REDIRECT
is used if an inactive user with a valid ticket
tries to login.
If ESIDOC_INACTIVE_USER_REDIRECT
is not set in the settings, it will take
the root path (i.e. /
) as default value.
Once your all set up, when a request to your app is made with the query string
esidoc_sso_id=<unique_uai>
, 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/?esidoc_sso_id=9990075c
In order to expose the Institutions
UAI number and end of subscription date, the following
API endpoint is available:
urlpatterns = [
...,
url(r"^institutions/$", InstitutionViewSet.as_view({'get': 'list'}), name="esidoc_institutions")
]
This endpoint is protected by a query string token authentication named token
.
The token value can be set in the settings.py of your app.
ESIDOC_ACCESS_TOKEN = 'my-secret-token-value'
Now when calling /esidoc/insitutions/?token=my-secret-token-value
, you will get a json response
with all your uai numbers (uai
) and ends of subscription (ends_at
). Here is an example:
[
{
"uai": "9990075C",
"ends_at": "2020-10-05"
},
{
"uai": "8880075C",
"ends_at": "2021-09-01"
}
]
Testing is managed by pytest
. Required package for testing can be installed with:
pip install -r test_requirements.txt
To run testing locally:
pytest