]> git.openstreetmap.org Git - osqa.git/commitdiff
some facebook oauth 2.0 fixes, use user id for following association, pass the access...
authorjordan <jordan@0cfe37f9-358a-4d5e-be75-b63607b5c754>
Fri, 16 Dec 2011 12:05:31 +0000 (12:05 +0000)
committerjordan <jordan@0cfe37f9-358a-4d5e-be75-b63607b5c754>
Fri, 16 Dec 2011 12:05:31 +0000 (12:05 +0000)
git-svn-id: http://svn.osqa.net/svnroot/osqa/trunk@1213 0cfe37f9-358a-4d5e-be75-b63607b5c754

forum/views/auth.py
forum_modules/facebookauth/authentication.py

index 9e7d6c6f828e92d43d76a79dfe90a18e712911d8..bac7639cf5cd8205c3dcf15e3e6929a6d3024a6f 100644 (file)
@@ -196,7 +196,11 @@ def external_register(request):
 
         provider_class = AUTH_PROVIDERS[auth_provider].consumer
 
-        user_data = provider_class.get_user_data(request.session['assoc_key'])
+        if provider_class.__class__.__name__ == 'FacebookAuthConsumer':
+            user_data = provider_class.get_user_data(request.session['access_token'])
+        else:
+            user_data = provider_class.get_user_data(request.session['assoc_key'])
+
 
         if not user_data:
             user_data = request.session.get('auth_consumer_data', {})
index 55cf16d88b4d986de0169b96b0be8d4a861fa2a4..8562bad60a2853649239daeb7a5b00a15cd4f40a 100644 (file)
@@ -44,16 +44,22 @@ class FacebookAuthConsumer(AuthenticationConsumer):
             response = cgi.parse_qs(urlopen("https://graph.facebook.com/oauth/access_token?" + urlencode(args)).read())
             access_token = response["access_token"][-1]
 
+
+            user_data = self.get_user_data(access_token)
+            assoc_key = user_data["id"]
+
             # Store the access token in cookie
-            request.session["assoc_key"] = access_token
+            request.session["access_token"] = access_token
+            request.session["assoc_key"] = assoc_key
 
-            return access_token
+            # Return the association key
+            return assoc_key
         except Exception, e:
             logging.error("Problem during facebook authentication: %s" % e)
             raise InvalidAuthentication(_("Something wrond happened during Facebook authentication, administrators will be notified"))
 
-    def get_user_data(self, assoc_key):
-        profile = load_json(urlopen("https://graph.facebook.com/me?" + urlencode(dict(access_token=assoc_key))))
+    def get_user_data(self, access_token):
+        profile = load_json(urlopen("https://graph.facebook.com/me?" + urlencode(dict(access_token=access_token))))
 
         name = profile["name"]
 
@@ -69,6 +75,7 @@ class FacebookAuthConsumer(AuthenticationConsumer):
 
         # Return the user data.
         return {
+            'id' : profile['id'],
             'username': name,
             'email': email,
         }