]> git.parisson.com Git - django-social-auth.git/commitdiff
Check linkedin error response. Closes #323
authorMatías Aguirre <matiasaguirre@gmail.com>
Mon, 23 Apr 2012 19:18:32 +0000 (16:18 -0300)
committerMatías Aguirre <matiasaguirre@gmail.com>
Mon, 23 Apr 2012 19:18:32 +0000 (16:18 -0300)
social_auth/backends/contrib/linkedin.py

index 1e2a7f871e2b2c1f2ce69d8cb745cf81672b7975..458e38ba688346681a6dc80599d815c9d203593c 100644 (file)
@@ -8,6 +8,7 @@ from xml.parsers.expat import ExpatError
 
 from social_auth.utils import setting
 from social_auth.backends import ConsumerBasedOAuth, OAuthBackend, USERNAME
+from social_auth.backends.exceptions import AuthCanceled, AuthUnknownError
 
 
 LINKEDIN_SERVER = 'linkedin.com'
@@ -62,6 +63,17 @@ class LinkedinAuth(ConsumerBasedOAuth):
         except (ExpatError, KeyError, IndexError):
             return None
 
+    def auth_complete(self, *args, **kwargs):
+        """Complete auth process. Check LinkedIn error response."""
+        oauth_problem = self.request.GET.get('oauth_problem')
+        if oauth_problem:
+            if oauth_problem == 'user_refused':
+                raise AuthCanceled(self, '')
+            else:
+                raise AuthUnknownError(self, 'LinkedIn error was %s' % \
+                                                    oauth_problem)
+        return super(LinkedinAuth, self).auth_complete(*args, **kwargs)
+
 
 def to_dict(xml):
     """Convert XML structure to dict recursively, repeated keys entries