]> git.parisson.com Git - django-social-auth.git/commitdiff
Move GoogleAppEngine backend to contrib and apply pep8. Refs #258.
authorMatías Aguirre <matiasaguirre@gmail.com>
Fri, 24 Feb 2012 11:47:40 +0000 (09:47 -0200)
committerMatías Aguirre <matiasaguirre@gmail.com>
Fri, 24 Feb 2012 11:47:48 +0000 (09:47 -0200)
social_auth/backends/contrib/gae.py [new file with mode: 0644]
social_auth/backends/gae.py [deleted file]

diff --git a/social_auth/backends/contrib/gae.py b/social_auth/backends/contrib/gae.py
new file mode 100644 (file)
index 0000000..fa6622c
--- /dev/null
@@ -0,0 +1,60 @@
+"""
+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
+
+
+class GAEBackend(SocialAuthBackend):
+    """GoogleAppengine authentication backend"""
+    name = 'google-appengine'
+
+    def get_user_id(self, details, response):
+        """Return current user id."""
+        user = users.get_current_user()
+        if user:
+            return user.user_id()
+
+    def get_user_details(self, response):
+        """Return user basic information (id and email only)."""
+        user = users.get_current_user()
+        return {USERNAME: user.user_id(),
+                'email': user.email(),
+                'fullname': '',
+                'first_name': '',
+                'last_name': ''}
+
+
+# Auth classes
+class GAEAuth(BaseAuth):
+    """GoogleAppengine authentication"""
+    AUTH_BACKEND = GAEBackend
+
+    def auth_url(self):
+        """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."""
+        if not users.get_current_user():
+            raise ValueError('Authentication error')
+
+        # 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,
+}
diff --git a/social_auth/backends/gae.py b/social_auth/backends/gae.py
deleted file mode 100644 (file)
index 35cc0b5..0000000
+++ /dev/null
@@ -1,61 +0,0 @@
-"""
-Google App Engine support using User API
-"""
-from __future__ import absolute_import
-
-from django.contrib.auth import authenticate
-
-from social_auth.backends import SocialAuthBackend, BaseAuth, USERNAME
-
-from google.appengine.api import users
-
-class GAEBackend(SocialAuthBackend):
-    """BrowserID authentication backend"""
-    name = 'google-appengine'
-
-    def get_user_id(self, details, response):
-        """Use BrowserID email as 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'}
-        user = users.get_current_user()
-        return {USERNAME: user.user_id(),
-                'email': user.email(),
-                'fullname': '',
-                'first_name': '',
-                'last_name': ''}
-
-# Auth classes
-class GAEAuth(BaseAuth):
-    """BrowserID authentication"""
-    AUTH_BACKEND = GAEBackend
-
-    def auth_url(self):
-        return users.create_login_url('/complete/gae/')
-
-    def auth_complete(self, *args, **kwargs):
-        """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 """
-        kwargs.update({
-            'response' : '',
-            self.AUTH_BACKEND.name: True
-        })
-
-        return authenticate(*args, **kwargs)
-
-# Backend definition
-BACKENDS = {
-    'gae': GAEAuth,
-}