Skip to main content

KU SSO for Django

This is a Django application written to support authentication via KU Single Sign-On (KU SSO) system.

Installation

Use pip to install the package from PyPI.

pip install kusso-django

Edit the project's settings.py to include the kusso_django.kusso app.

INSTALLED_APPS = [
    :
    'kusso_django.kusso',
]

Synchronize the database with the command

./manage.py migrate

Edit the project's urls.py to include necessary paths. A different prefix may be used, but the redirect URI needs to be changed accordingly.

from django.urls import path, include
urlpatterns = [
    :
    path('kusso', include('kusso_django.kusso.urls', namespace='kusso'))
]

With the example above, the redirect URI to be requested to the Office of Computer Services will be:

https://<host>/<subpath>/kusso/authorize/

Add KUSSO_CONFIG to settings.py with the client ID and secret given by the Office of Computer Services. The create_new_user flag indicates whether a non-existent user will be automatically created upon successful login from KU SSO.

KUSSO_CONFIG = {
    'client_id': '<client-id>',
    'client_secret': '<client-secret>',
    'create_new_user': <True or False>,
}

Login/Logout Template Tags

Assuming the URL namespace is kusso, use the url template tag to generate login and logout links:

  • Login link
    <a href="{% url 'kusso:login' %}?next={{ request.GET.next }}">KU All-Login</a>
    
  • Logout link
    <a href="{% url 'kusso:logout' %}">Logout</a>
    

Error Handling

When an error is encountered during the authentication process, the user will be sent back to the login page. A corresponding error message is also sent as a message via Django's messages framework. To make the error message visible to the user, the login template must include something like:

{% if messages %}
<ul class="messages">
    {% for message in messages %}
    <li{% if message.tags %} class="{{ message.tags }}"{% endif %}>{{ message }}</li>
    {% endfor %}
</ul>
{% endif %}

Deploying App with Reverse Proxy

To ensure the redirect-uri for KU SSO is constructed correctly when deploying the project behind a reverse proxy like Nginx, add the following configurations to the project's settings.py.

USE_X_FORWARDED_HOST = True
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')

Release files for kusso-django 1.1.6

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for kusso-django 1.1.6
File Size Uploaded
kusso_django-1.1.6.tar.gz 4.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for kusso-django 1.1.6
File Interpreter ABI Platform
kusso_django-1.1.6-py3-none-any.whl Python 3 none any Details

Total release size: 11.4 kB

Release files / kusso_django-1.1.6.tar.gz

Download URL kusso_django-1.1.6.tar.gz
Size 4.9 kB
Tags Source
SHA-256 checksum
How to use checksums
e920a439b989d985095c6c1478c3b57b55d9e363768919d7a2b6b7752a78a327
BLAKE2b-256 checksum
How to use checksums
98d46a73691e9d4d71433c09b396f59586c40f164dc253e062cb2b05a1b67160
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.11.3

Release files / kusso_django-1.1.6-py3-none-any.whl

Download URL kusso_django-1.1.6-py3-none-any.whl
Size 6.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
478279d862018a99a67d76987d8a80ce077cc8c528bd075ad485a47a036b4172
BLAKE2b-256 checksum
How to use checksums
fcec205da403f1ae4b463707067207a766d260d58bb175cde8232446b2dfd092
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.11.3

Release history Release notifications | RSS feed

This release

1.1.6 This release

2 release files

1.1.5

2 release files

1.1.4

2 release files

1.1.3

2 release files

1.1.2

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page