retrieve proxy from openid
authorMaciej Tronowski <mtro@man.poznan.pl>
Mon, 16 Feb 2015 16:06:49 +0000 (17:06 +0100)
committerMaciej Tronowski <mtro@man.poznan.pl>
Mon, 16 Feb 2015 16:06:49 +0000 (17:06 +0100)
qcg/__init__.py
qcg/apps.py [new file with mode: 0644]
qcg/signals.py [new file with mode: 0644]
qcg/templates/qcg/base.html
qcg/urls.py
qcg/views.py

index e69de29..0d84906 100644 (file)
@@ -0,0 +1 @@
+default_app_config = 'qcg.apps.QCGPortalConfig'
diff --git a/qcg/apps.py b/qcg/apps.py
new file mode 100644 (file)
index 0000000..b2d04bb
--- /dev/null
@@ -0,0 +1,9 @@
+from django.apps import AppConfig
+
+
+class QCGPortalConfig(AppConfig):
+    name = 'qcg'
+    verbose_name = "Portal QCG"
+
+    def ready(self):
+        import signals
diff --git a/qcg/signals.py b/qcg/signals.py
new file mode 100644 (file)
index 0000000..8f7b8db
--- /dev/null
@@ -0,0 +1,14 @@
+from django.dispatch import receiver
+from django_openid_auth.signals import openid_login_complete
+from openid.extensions import ax
+
+
+@receiver(openid_login_complete)
+def post_openid_login(sender, request, openid_response, **kwargs):
+    fetch_response = ax.FetchResponse.fromSuccessResponse(openid_response)
+    if fetch_response:
+        proxy = fetch_response.getSingle('http://openid.plgrid.pl/certificate/proxy')
+        user_cert = fetch_response.getSingle('http://openid.plgrid.pl/certificate/userCert')
+        proxy_priv_key = fetch_response.getSingle('http://openid.plgrid.pl/certificate/proxyPrivKey')
+
+        request.session['proxy'] = (proxy + proxy_priv_key + user_cert).replace('<br>', '\n')
index bbb29f3..fcf6291 100644 (file)
@@ -1,4 +1,5 @@
 {% load staticfiles webdesign %}
+{% load firstof from future %}
 
 <!DOCTYPE html>
 <html lang="pl">
index c48f41b..de1a7e3 100644 (file)
@@ -3,9 +3,9 @@ from django.conf.urls import patterns, url, include
 from qcg import views
 
 urlpatterns = patterns('',
-    url(r'^openid/login/', views.openid_login, name='openid-login'),
+    url(r'^openid/login/', views.openid_begin, name='openid-login'),
+    url(r'^openid/complete/', 'django_openid_auth.views.login_complete', name='openid-complete'),
     url(r'^openid/logout/', 'django.contrib.auth.views.logout', {'template_name': 'qcg/logout.html'}, name='logout'),
-    url(r'^openid/', include('django_openid_auth.urls')),
 
     url(r'^$', views.index, name='index'),
     url(r'^jobs/$', views.jobs_list, name='jobs'),
index bff6d17..eb54d58 100644 (file)
@@ -12,16 +12,16 @@ def index(request):
     return render(request, 'qcg/base.html')
 
 
-def openid_login(request):
+def openid_begin(request):
     openid_request = make_consumer(request).begin(settings.OPENID_SSO_SERVER_URL)
 
     fetch_request = ax.FetchRequest()
     for (attr, alias) in [('http://axschema.org/namePerson/friendly', 'nickname'),
                           ('http://axschema.org/contact/email', 'email'),
                           ('http://axschema.org/namePerson', 'fullname'),
-                          # ('http://openid.plgrid.pl/certificate/proxy', 'proxy'),
-                          # ('http://openid.plgrid.pl/certificate/userCert', 'userCert'),
-                          # ('http://openid.plgrid.pl/certificate/proxyPrivKey', 'proxyPrivKey'),
+                          ('http://openid.plgrid.pl/certificate/proxy', 'proxy'),
+                          ('http://openid.plgrid.pl/certificate/userCert', 'userCert'),
+                          ('http://openid.plgrid.pl/certificate/proxyPrivKey', 'proxyPrivKey'),
                           ('http://openid.plgrid.pl/POSTresponse', 'POSTresponse')]:
         fetch_request.add(ax.AttrInfo(attr, alias=alias, required=True))
     openid_request.addExtension(fetch_request)