]> git.parisson.com Git - django-social-auth.git/commitdiff
Catch OAuth 400 response when user denies access. Closes #260
authorMatías Aguirre <matiasaguirre@gmail.com>
Mon, 20 Feb 2012 17:14:42 +0000 (15:14 -0200)
committerMatías Aguirre <matiasaguirre@gmail.com>
Mon, 20 Feb 2012 17:14:42 +0000 (15:14 -0200)
social_auth/backends/__init__.py

index b4a59a4944a5b2a3d1a20ca43e84cc9ccd57f84f..ea7e3a8b164d8bce12d589a084e50e999cd5438d 100644 (file)
@@ -9,7 +9,7 @@ Also the modules *must* define a BACKENDS dictionary with the backend name
 (which is used for URLs matching) and Auth class, otherwise it won't be
 enabled.
 """
-from urllib2 import Request, urlopen
+from urllib2 import Request, urlopen, HTTPError
 from urllib import urlencode
 from urlparse import urlsplit
 
@@ -523,7 +523,14 @@ class ConsumerBasedOAuth(BaseOAuth):
         if token.key != self.data.get('oauth_token', 'no-token'):
             raise ValueError('Incorrect tokens')
 
-        access_token = self.access_token(token)
+        try:
+            access_token = self.access_token(token)
+        except HTTPError, e:
+            if e.code == 400:
+                raise ValueError('User denied access')
+            else:
+                raise
+
         data = self.user_data(access_token)
         if data is not None:
             data['access_token'] = access_token.to_string()