Implement single sign-out with community auth 2.0
authorMagnus Hagander <magnus@hagander.net>
Tue, 27 Dec 2011 18:36:49 +0000 (19:36 +0100)
committerMagnus Hagander <magnus@hagander.net>
Tue, 27 Dec 2011 18:36:49 +0000 (19:36 +0100)
hamnadmin/auth.py
hamnadmin/register/urls.py

index 31bac86eef969983dbfdb80a7da7feeac2caf16d..8b02de1c8f4ca8325d597faea793d3478a7a1730 100644 (file)
@@ -18,6 +18,7 @@ from django.http import HttpResponseRedirect
 from django.contrib.auth.models import User
 from django.contrib.auth.backends import ModelBackend
 from django.contrib.auth import login as django_login
+from django.contrib.auth import logout as django_logout
 from django.conf import settings
 
 import base64
@@ -47,9 +48,20 @@ def login(request):
        else:
                return HttpResponseRedirect(settings.PGAUTH_REDIRECT)
 
+# Handle logout requests by logging out of this site and then
+# redirecting to log out from the main site as well.
+def logout(request):
+       if request.user.is_authenticated():
+               django_logout(request)
+       return HttpResponseRedirect("%slogout/" % settings.PGAUTH_REDIRECT)
+
 # Receive an authentication response from the main website and try
 # to log the user in.
 def auth_receive(request):
+       if request.GET.has_key('s') and request.GET['s'] == "logout":
+               # This was a logout request
+               return HttpResponseRedirect('/')
+
        if not request.GET.has_key('i'):
                raise Exception("Missing IV")
        if not request.GET.has_key('d'):
index 81089f498c7c3662322dd8c81f2a508f26a9623a..27a0b5fa1292a64a412c270ceb98997198ab0d7f 100644 (file)
@@ -1,5 +1,4 @@
 from django.conf.urls.defaults import *
-from django.contrib.auth.views import logout, logout_then_login
 
 # Uncomment the next two lines to enable the admin:
 from django.contrib import admin
@@ -20,7 +19,7 @@ urlpatterns = patterns('',
 
     (r'^login/$', 'hamnadmin.auth.login'),
     (r'^auth_receive/$', 'hamnadmin.auth.auth_receive'),
-    (r'^logout/$', logout_then_login, {'login_url':'/'}),
+    (r'^logout/$', 'hamnadmin.auth.logout'),
 
     (r'^admin/', include(admin.site.urls)),
 )