]> git.parisson.com Git - django-social-auth.git/commitdiff
updated docs and better exception handling when a user declines the Auth connection
authorHassek <nullwriter@gmail.com>
Mon, 4 Jun 2012 17:12:51 +0000 (12:42 -0430)
committerHassek <nullwriter@gmail.com>
Mon, 4 Jun 2012 17:12:51 +0000 (12:42 -0430)
doc/backends/evernote.rst
social_auth/backends/contrib/evernote.py

index 25a17a881e8f366bc131b366b584257ae756f855..0d5f5679916b85c2441069b4f4c7779673c50ae5 100644 (file)
@@ -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
index 1e728d5b2e64e93456cc28103e5702c385124249..71d93730ac2561fca3a54117532e4a1cf96921fa 100644 (file)
@@ -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