This branch is a Python 3 port from the original repository.
Check KAIST Single Auth Service v3.0 official document.
Tested with Python 3.5.1, Django 1.9.7, requests 2.10.0 on Ubuntu 16.0.4.
It is recommended to use virtualenv to make your python project would be independent to others.
$ cd {BASE_DIR of your django project}
$ git clone -b support/python-3.5 https://github.com/HangPark/DJANGO4KAIST
$ mv DJANGO4KAIST/ksso .
$ pip install -r DJANGO4KAIST/requirements.txt
$ rm -rf DJANGO4KAIST-
Add this app into your django project by editting
settings.pyof it. -
Configure
ksso/settings.pyvariables:PORTAL_ADMIN_ID- Portal ID of a person can access the system. (usually the manager of your site)PORTAL_ADMIN_PW- Portal password of a person can access the system.PORTAL_PUBLIC_KEY- Public key of your site issued by KAISTPORTAL_LOGIN_URL- Login page of KAIST single auth system.PORTAL_TARGET_URL- Targeting page for SOAP request to get user infos.AUTH_REDIRECT_URL- Default url after authorization if redirection url was not given.
-
Implement
TODOinksso/models.pyandksso/classes.pyfor additional SOAP fields. -
python makemigrations ksso -
python migrate ksso -
Attach
ksso.views.LoginViewandksso.views.LogoutViewto your login & out url, respectively by usingas_view()inurls.pyof your project like below:
...
from ksso.views import LoginView, LogoutView
...
urlpatterns = [
...
url(r'^user/login/$', LoginView.as_view()),
url(r'^user/logout/$', LogoutView.as_view()),
...
]In comparison to the previous version, requests module is used instead of urllib or urllib2. Moreover, it became possible to specify a redirection url after authrization.
To specify redirection url after authrization, you can add it to the GET parameter next. For example, if the login url is /user/login and user should move to /article/123 after login successful, you can use /user/login?next=/article/123 for login url.
This feature is implemented by using cookie named REDIRECT_URL_TOKEN because the KAIST single auth service can not pass the custom redirect url.