]> git.parisson.com Git - django-social-auth.git/commitdiff
Add a social_auth wrapper backend around the Google App Engine User API.
authorUser <user@goku.localdomain>
Fri, 17 Feb 2012 18:04:23 +0000 (13:04 -0500)
committerUser <user@goku.localdomain>
Fri, 17 Feb 2012 18:04:23 +0000 (13:04 -0500)
social_auth/backends/gae.py [new file with mode: 0644]

diff --git a/social_auth/backends/gae.py b/social_auth/backends/gae.py
new file mode 100644 (file)
index 0000000..ede1c0b
--- /dev/null
@@ -0,0 +1,54 @@
+"""
+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 = 'GAE'
+
+    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()
+
+    def auth_complete(self, *args, **kwargs):
+        """Completes loging process, must return user instance"""
+        if not users.get_current_user():
+            raise ValueError('Authentication error')
+
+        return authenticate(*args, **kwargs)
+
+# Backend definition
+BACKENDS = {
+    'gae': GAEAuth,
+}