From 1200e2ceed78d84eb7dd0efb40d840a20d4e756e Mon Sep 17 00:00:00 2001 From: =?utf8?q?Mat=C3=ADas=20Aguirre?= Date: Mon, 20 Feb 2012 15:14:42 -0200 Subject: [PATCH] Catch OAuth 400 response when user denies access. Closes #260 --- social_auth/backends/__init__.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/social_auth/backends/__init__.py b/social_auth/backends/__init__.py index b4a59a4..ea7e3a8 100644 --- a/social_auth/backends/__init__.py +++ b/social_auth/backends/__init__.py @@ -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() -- 2.39.5