From c516e2c8f1b03b60258b6b5d35b83eea608353b6 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Mat=C3=ADas=20Aguirre?= Date: Fri, 24 Feb 2012 09:47:40 -0200 Subject: [PATCH] Move GoogleAppEngine backend to contrib and apply pep8. Refs #258. --- social_auth/backends/{ => contrib}/gae.py | 29 +++++++++++------------ 1 file changed, 14 insertions(+), 15 deletions(-) rename social_auth/backends/{ => contrib}/gae.py (66%) diff --git a/social_auth/backends/gae.py b/social_auth/backends/contrib/gae.py similarity index 66% rename from social_auth/backends/gae.py rename to social_auth/backends/contrib/gae.py index 35cc0b5..fa6622c 100644 --- a/social_auth/backends/gae.py +++ b/social_auth/backends/contrib/gae.py @@ -3,29 +3,26 @@ Google App Engine support using User API """ from __future__ import absolute_import +from google.appengine.api import users + from django.contrib.auth import authenticate +from django.core.urlresolvers import reverse from social_auth.backends import SocialAuthBackend, BaseAuth, USERNAME -from google.appengine.api import users class GAEBackend(SocialAuthBackend): - """BrowserID authentication backend""" + """GoogleAppengine authentication backend""" name = 'google-appengine' def get_user_id(self, details, response): - """Use BrowserID email as ID""" + """Return current user id.""" user = users.get_current_user() if user: return user.user_id() def get_user_details(self, response): - """Return user details, BrowserID only provides Email.""" - # {'status': 'okay', - # 'audience': 'localhost:8000', - # 'expires': 1328983575529, - # 'email': 'name@server.com', - # 'issuer': 'browserid.org'} + """Return user basic information (id and email only).""" user = users.get_current_user() return {USERNAME: user.user_id(), 'email': user.email(), @@ -33,28 +30,30 @@ class GAEBackend(SocialAuthBackend): 'first_name': '', 'last_name': ''} + # Auth classes class GAEAuth(BaseAuth): - """BrowserID authentication""" + """GoogleAppengine authentication""" AUTH_BACKEND = GAEBackend def auth_url(self): - return users.create_login_url('/complete/gae/') + """Build and return complete URL.""" + return users.create_login_url(reverse('socialauth_complete', + args=(self.AUTH_BACKEND.name,))) def auth_complete(self, *args, **kwargs): - """Completes login process, must return user instance""" - + """Completes login process, must return user instance.""" if not users.get_current_user(): raise ValueError('Authentication error') - """ Setting these two are necessary for BaseAuth.authenticate to work """ + # Setting these two are necessary for BaseAuth.authenticate to work kwargs.update({ 'response' : '', self.AUTH_BACKEND.name: True }) - return authenticate(*args, **kwargs) + # Backend definition BACKENDS = { 'gae': GAEAuth, -- 2.39.5