Skip to content

Commit

Permalink
doc updates
Browse files Browse the repository at this point in the history
  • Loading branch information
jcarbaugh committed Aug 27, 2010
1 parent 21a2776 commit acdf975
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 18 deletions.
2 changes: 1 addition & 1 deletion googleauth/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
)
35 changes: 22 additions & 13 deletions googleauth/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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')

Expand All @@ -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),
Expand All @@ -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)
8 changes: 4 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
@@ -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",
Expand Down

0 comments on commit acdf975

Please sign in to comment.