]> git.parisson.com Git - django-social-auth.git/commitdiff
Raise exception if Facebook response is malformed. Refs #320
authorMatías Aguirre <matiasaguirre@gmail.com>
Mon, 23 Apr 2012 18:53:53 +0000 (15:53 -0300)
committerMatías Aguirre <matiasaguirre@gmail.com>
Mon, 23 Apr 2012 18:53:53 +0000 (15:53 -0300)
social_auth/backends/facebook.py

index cdf1cf6f3f8bd8ed883c01a2a0b44d77539e77e6..b1fbbbcdb2843350b922b9931cb2b8721528a9de 100644 (file)
@@ -21,7 +21,8 @@ from django.contrib.auth import authenticate
 from social_auth.backends import BaseOAuth2, OAuthBackend, USERNAME
 from social_auth.utils import sanitize_log_data, setting, log
 from social_auth.backends.exceptions import AuthException, AuthCanceled, \
-                                            AuthFailed, AuthTokenError
+                                            AuthFailed, AuthTokenError, \
+                                            AuthUnknownError
 
 
 # Facebook configuration
@@ -104,12 +105,20 @@ class FacebookAuth(BaseOAuth2):
         access_token = response['access_token'][0]
         data = self.user_data(access_token)
 
-        if isinstance(data, dict):
-            data['access_token'] = access_token
-            # expires will not be part of response if offline access
-            # premission was requested
-            if 'expires' in response:
-                data['expires'] = response['expires'][0]
+        if not isinstance(data, dict):
+            # From time to time Facebook responds back a JSON with just False
+            # as value, the reason is still unknown, but since the data is
+            # needed (it contains the user ID used to identify the account on
+            # further logins), this app cannot allow it to continue with the
+            # auth process.
+            raise AuthUnknownError(self, 'An error ocurred while retrieving '\
+                                         'users Facebook data')
+
+        data['access_token'] = access_token
+        # expires will not be part of response if offline access premission was
+        # requested
+        if 'expires' in response:
+            data['expires'] = response['expires'][0]
 
         kwargs.update({'auth': self,
                        'response': data,