Skip to main content

Django app for KU SSO authentication

Project description

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 directly from the repo on GitLab.

pip install git+https://gitlab.com/cjaikaeo/kusso-django.git

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')

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

kusso_django-1.1.2.tar.gz (5.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

kusso_django-1.1.2-py3-none-any.whl (6.9 kB view details)

Uploaded Python 3

File details

Details for the file kusso_django-1.1.2.tar.gz.

File metadata

  • Download URL: kusso_django-1.1.2.tar.gz
  • Upload date:
  • Size: 5.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.11.3 Darwin/23.6.0

File hashes

Hashes for kusso_django-1.1.2.tar.gz
Algorithm Hash digest
SHA256 5f12e331e23064cb14cda4d38ebb5c033acabe42fc6fd7233e8e0b196f54f371
MD5 6c43a94a433e36c03f6ccad976972918
BLAKE2b-256 3feba4edd306caf0e12366357ef51ae0c5bd2b93f00e342bcdb18ff818415596

See more details on using hashes here.

File details

Details for the file kusso_django-1.1.2-py3-none-any.whl.

File metadata

  • Download URL: kusso_django-1.1.2-py3-none-any.whl
  • Upload date:
  • Size: 6.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.11.3 Darwin/23.6.0

File hashes

Hashes for kusso_django-1.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 7920696c84d4b67add20fc2ab5ec604d0976ba10fa8dd2ba5c4e2de73cd44e4a
MD5 0469518dc51cadd48222aaed854d4261
BLAKE2b-256 7fe8b3595984a275ea0d3b988f0f8e90ba81fa27d9b73b985e5b2c75e51d3b5a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page