From acdf97552f58e28d0ca53e9c4c136da80379b609 Mon Sep 17 00:00:00 2001 From: Jeremy Carbaugh Date: Fri, 27 Aug 2010 17:50:14 -0400 Subject: [PATCH] doc updates --- googleauth/urls.py | 2 +- googleauth/views.py | 35 ++++++++++++++++++++++------------- setup.py | 8 ++++---- 3 files changed, 27 insertions(+), 18 deletions(-) diff --git a/googleauth/urls.py b/googleauth/urls.py index b8f7fa3..c1100f9 100644 --- a/googleauth/urls.py +++ b/googleauth/urls.py @@ -2,6 +2,6 @@ urlpatterns = patterns('', url(r'^login/$', 'googleauth.views.login', name='googleauth_login'), - url(r'^auth/$', 'googleauth.views.callback', name='googleauth_callback'), + url(r'^callback/$', 'googleauth.views.callback', name='googleauth_callback'), url(r'^logout/$', 'googleauth.views.logout', name='googleauth_logout'), ) \ No newline at end of file diff --git a/googleauth/views.py b/googleauth/views.py index 94271dc..16c75b1 100644 --- a/googleauth/views.py +++ b/googleauth/views.py @@ -8,24 +8,28 @@ from openid.yadis.discover import DiscoveryFailure import urllib -if hasattr(settings, 'GOOGLEAUTH_DOMAIN'): - OPENID_ENDPOINT = "https://www.google.com/accounts/o8/site-xrds?hd=%s" % settings.GOOGLEAUTH_DOMAIN -else: - OPENID_ENDPOINT = "https://www.google.com/accounts/o8/id" - - def login(request): + """ Redirect user to appropriate Google authentication URL. + Uses attribute exchange to get user's name and email address. + """ - request.session['login_referer'] = request.META.get('HTTP_REFERER', None) + request.session['next'] = request.META.get('HTTP_REFERER', None) openid_consumer = Consumer(request.session, None) + # generate appropriate endpoint based on whether Google or Apps account is used + if hasattr(settings, 'GOOGLEAUTH_DOMAIN'): + endpoint = "https://www.google.com/accounts/o8/site-xrds?hd=%s" % settings.GOOGLEAUTH_DOMAIN + else: + endpoint = "https://www.google.com/accounts/o8/id" + + # try request try: - auth_request = openid_consumer.begin(OPENID_ENDPOINT) + auth_request = openid_consumer.begin(endpoint) except DiscoveryFailure, df: - return HttpResponse("%s" % df) + return HttpResponseServerError("%s" % df) - # this is where attribute exchange stuff should be added + # attribute exchange to get email, firstname, and lastname extras = { "openid.ns.ax": "http://openid.net/srv/ax/1.0", "openid.ax.mode": "fetch_request", @@ -36,10 +40,8 @@ def login(request): } # generate callback URL - scheme = 'https' if request.is_secure() else 'http' realm_default = 'localhost:8000' if settings.DEBUG else Site.objects.get_current().domain - realm = '%s://%s' % (scheme, getattr(settings, 'GOOGLEAUTH_REALM', realm_default)) cb_url = realm + reverse('googleauth.views.callback') @@ -49,9 +51,13 @@ def login(request): return HttpResponseRedirect("%s&%s" % (url, urllib.urlencode(extras))) def callback(request): + """ Handle callback from Google authentication. + Logs user in if the callback was successful. + """ identity = request.GET.get('openid.identity') + # extract ax attributes from response attributes = { 'firstname': request.GET.get('openid.ext1.value.firstname', None), 'lastname': request.GET.get('openid.ext1.value.lastname', None), @@ -63,8 +69,11 @@ def callback(request): return HttpResponseServerError('user account not found') auth.login(request, user) - redirect = request.session.get('login_referer', None) + redirect = request.session.get('next', None) return HttpResponseRedirect(redirect or '/') def logout(request): + """ Log user out of Django application. + Does not log out of user's Google account. + """ return django_logout(request) \ No newline at end of file diff --git a/setup.py b/setup.py index 5e6a5da..a01fb83 100644 --- a/setup.py +++ b/setup.py @@ -1,16 +1,16 @@ from distutils.core import setup -long_description = open('README.md').read() +#long_description = open('README.md').read() setup( name="django-googleauth", version='0.1', py_modules=["googleauth"], - description="OpenID authentication for sunlightfoundation.com accounts", + description="OpenID authentication Google and Google Apps accounts", author="Jeremy Carbaugh", - author_email = "jcarbaugh@sunlightfoundation.com", + author_email = "jcarbaugh@gmail.com", license='BSD', - long_description=long_description, + #long_description=long_description, platforms=["any"], classifiers=[ "Development Status :: 4 - Beta",