From: Hassek Date: Mon, 4 Jun 2012 17:12:51 +0000 (-0430) Subject: updated docs and better exception handling when a user declines the Auth connection X-Git-Url: https://git.parisson.com/?a=commitdiff_plain;h=34ee64a0f22d6133f3322723b35daf88bc4a12c6;p=django-social-auth.git updated docs and better exception handling when a user declines the Auth connection --- diff --git a/doc/backends/evernote.rst b/doc/backends/evernote.rst index 25a17a8..0d5f567 100644 --- a/doc/backends/evernote.rst +++ b/doc/backends/evernote.rst @@ -10,4 +10,8 @@ Evernote OAuth 1.0 workflow. EVERNOTE_CONSUMER_KEY = '' EVERNOTE_CONSUMER_SECRET = '' +- To test in the sandbox add to settings:: + + EVERNOTE_DEBUG = True + .. _Evernote API Key form: http://dev.evernote.com/support/api_key.php diff --git a/social_auth/backends/contrib/evernote.py b/social_auth/backends/contrib/evernote.py index 1e728d5..71d9373 100644 --- a/social_auth/backends/contrib/evernote.py +++ b/social_auth/backends/contrib/evernote.py @@ -3,6 +3,7 @@ EverNote OAuth support No extra configurations are needed to make this work. """ +from urllib2 import HTTPError try: from urlparse import parse_qs parse_qs # placate pyflakes @@ -12,7 +13,8 @@ except ImportError: from oauth2 import Token from social_auth.utils import setting -from social_auth.backends import ConsumerBasedOAuth, OAuthBackend, USERNAME +from social_auth.backends import ConsumerBasedOAuth, OAuthBackend, USERNAME,\ + exceptions if setting('EVERNOTE_DEBUG', False): @@ -75,7 +77,16 @@ class EvernoteAuth(ConsumerBasedOAuth): def access_token(self, token): """Return request for access token value""" request = self.oauth_request(token, self.ACCESS_TOKEN_URL) - response = self.fetch_response(request) + + try: + response = self.fetch_response(request) + except HTTPError, e: + # Evernote returns a 401 error when AuthCanceled + if e.code == 401: + raise exceptions.AuthCanceled(self) + else: + raise + params = parse_qs(response) # evernote sents a empty secret token, this way it doesn't fires up the