Skip to content

Commit

Permalink
Add readme and setup.py
Browse files Browse the repository at this point in the history
  • Loading branch information
fatanugraha committed Mar 7, 2019
1 parent 1fc7b48 commit 223f457
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 5 deletions.
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include django_sso_ui/additional-info.json
44 changes: 44 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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`.
2 changes: 1 addition & 1 deletion django_sso_ui/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions django_sso_ui/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand Down
29 changes: 29 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -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="[email protected]",
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"],
)
4 changes: 2 additions & 2 deletions tests/urls.py
Original file line number Diff line number Diff line change
@@ -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))

Expand Down

0 comments on commit 223f457

Please sign in to comment.