From 223f4575707c53b05cfdaef9b7679924b1507548 Mon Sep 17 00:00:00 2001 From: Fata Nugraha Date: Thu, 7 Mar 2019 22:50:13 +0700 Subject: [PATCH] Add readme and setup.py --- MANIFEST.in | 1 + README.md | 44 +++++++++++++++++++++++++++++++++++++ django_sso_ui/decorators.py | 2 +- django_sso_ui/utils.py | 4 ++-- setup.py | 29 ++++++++++++++++++++++++ tests/urls.py | 4 ++-- 6 files changed, 79 insertions(+), 5 deletions(-) create mode 100644 MANIFEST.in create mode 100644 README.md create mode 100644 setup.py diff --git a/MANIFEST.in b/MANIFEST.in new file mode 100644 index 0000000..8b4544d --- /dev/null +++ b/MANIFEST.in @@ -0,0 +1 @@ +include django_sso_ui/additional-info.json diff --git a/README.md b/README.md new file mode 100644 index 0000000..0d8197b --- /dev/null +++ b/README.md @@ -0,0 +1,44 @@ +# django-sso-ui + +Sebuah library python untuk memudahkan aplikasi django menggunakan SSO +Universitas Indonesia. + +## Instalasi + +`pip install django-sso-ui` + +## Cara Menggunakan + +Pertama import decorator `with_sso_ui` +`from django_sso_ui.decorators import with_sso_ui` + +Lalu wrap ke view yang membutuhkan info user sso ui. Jangan lupa tambahkan parameter `sso_profile` pada fungsi view yang di wrap. + +```py +@with_sso_ui +def login(request, sso_profile): + return HttpResponse(json.dumps(sso_profile)) +``` + +Apabila pengguna tidak diharuskan login dengan SSO untuk mengakses view tersebut, tambahkan parameter `force_login=False` pada decorator. + +```py +@with_sso_ui(force_login=False) +def login(request, sso_profile): + return HttpResponse(json.dumps(sso_profile)) +``` + +## Settings + +Untuk mengubah endpoint cas yang digunakan, terdapat opsi di tambahkan +line berikut di `settings.py` dengan endpoint yang diinginkan +`SSO_UI_URL="https://sso.ui.ac.id/cas2/"` + +Untuk memaksa library untuk menggunakan `https` untuk url callback setelah +login CAS berhasil, tambahkan line berikut di `settings.py` +`SSO_UI_FORCE_SERVICE_HTTPS=True` + +## Notes + +Informasi tambahan seperti fakultas, study_program hanya bisa didapatkan +apabila menggunakan `https://sso.ui.ac.id/cas2`. diff --git a/django_sso_ui/decorators.py b/django_sso_ui/decorators.py index a0de809..e751bad 100644 --- a/django_sso_ui/decorators.py +++ b/django_sso_ui/decorators.py @@ -17,7 +17,7 @@ ) -def with_sso_login(force_login=True): +def with_sso_ui(force_login=True): def decorator(func): def wrapper(request, *args, **kwargs): service_url = get_service_url(request) diff --git a/django_sso_ui/utils.py b/django_sso_ui/utils.py index 0915390..ff823a3 100644 --- a/django_sso_ui/utils.py +++ b/django_sso_ui/utils.py @@ -10,7 +10,7 @@ def normalize_username(username): def get_protocol(request): - if request.is_secure() or django_settings.SSO_FORCE_SERVICE_HTTPS: + if request.is_secure() or django_settings.SSO_UI_FORCE_SERVICE_HTTPS: return "https" return "http" @@ -25,7 +25,7 @@ def get_service_url(request, redirect_to=None): def get_cas_client(service_url=None, request=None): - server_url = django_settings.SSO_URL + server_url = django_settings.SSO_UI_URL if server_url and request and server_url.startswith("/"): scheme = request.META.get("X-Forwarded-Proto", request.scheme) server_url = scheme + "://" + request.META["HTTP_HOST"] + server_url diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..d4f3e38 --- /dev/null +++ b/setup.py @@ -0,0 +1,29 @@ +import pathlib +from setuptools import setup + +# The directory containing this file +HERE = pathlib.Path(__file__).parent + +# The text of the README file +README = (HERE / "README.md").read_text() + +# This call to setup() does all the work +setup( + name="django-sso-ui", + version="1.0.0", + description="A simple SSO UI CAS wrapper for Django", + long_description=README, + long_description_content_type="text/markdown", + url="https://github.com/RistekCSUI/django-sso", + author="Fata Nugraha", + author_email="fatanugraha@outlook.com", + license="MIT", + classifiers=[ + "License :: OSI Approved :: MIT License", + "Programming Language :: Python :: 3", + "Programming Language :: Python :: 3.6", + ], + packages=["django_sso_ui"], + include_package_data=True, + install_requires=["python-cas", "django"], +) diff --git a/tests/urls.py b/tests/urls.py index 53dbee1..f369120 100644 --- a/tests/urls.py +++ b/tests/urls.py @@ -1,10 +1,10 @@ from django.urls import path from django.http import HttpResponse -from django_sso_ui.decorators import with_sso_login +from django_sso_ui.decorators import with_sso_ui import json -@with_sso_login(force_login=True) +@with_sso_ui(force_login=True) def login(request, sso_profile): return HttpResponse(json.dumps(sso_profile))