]> git.parisson.com Git - django-social-auth.git/commitdiff
added support for evernote sandbox
authorHassek <nullwriter@gmail.com>
Fri, 4 May 2012 00:32:57 +0000 (20:02 -0430)
committerHassek <nullwriter@gmail.com>
Fri, 4 May 2012 00:32:57 +0000 (20:02 -0430)
social_auth/backends/contrib/evernote.py

index 36ae5d75eabe6da1201ab0b4132b9fb0933de0a1..04372bef33bd61c77f8d69fbfee79f95e0224a8c 100644 (file)
@@ -11,11 +11,15 @@ except ImportError:
     from cgi import parse_qs
 
 from oauth2 import Token
+from social_auth.utils import setting
 from social_auth.backends import ConsumerBasedOAuth, OAuthBackend, USERNAME
 
 
-EVERNOTE_SERVER = "sandbox.evernote.com"
-#EVERNOTE_SERVER = 'www.evernote.com'
+if setting('EVERNOTE_DEBUG', False):
+    EVERNOTE_SERVER = "sandbox.evernote.com"
+else:
+    EVERNOTE_SERVER = 'www.evernote.com'
+
 EVERNOTE_REQUEST_TOKEN_URL = 'https://%s/oauth' % \
                                     EVERNOTE_SERVER
 EVERNOTE_ACCESS_TOKEN_URL = 'https://%s/oauth' % \
@@ -27,20 +31,9 @@ EVERNOTE_AUTHORIZATION_URL = 'https://%s/OAuth.action' % \
 class EvernoteBackend(OAuthBackend):
     """Evernote OAuth authentication backend"""
     name = 'evernote'
-    #EXTRA_DATA = [('id', 'id'),
-                  #('first-name', 'first_name'),
-                  #('last-name', 'last_name')]
 
     def get_user_details(self, response):
         """Return user details from Evernote account"""
-        """
-        {'edam_expires': ['1367525289541'],
-         'edam_noteStoreUrl': ['https://sandbox.evernote.com/shard/s1/notestore'],
-         'edam_shard': ['s1'],
-         'edam_userId': ['123841'],
-         'edam_webApiUrlPrefix': ['https://sandbox.evernote.com/shard/s1/'],
-         'oauth_token': ['S=s1:U=1e3c1:E=13e66dbee45:C=1370f2ac245:P=185:A=onereceipt:H=411443c5e8b20f8718ed382a19d4ae38']}
-        """
         return {USERNAME: response["edam_userId"],
                 'email': '',
                 }
@@ -59,24 +52,30 @@ class EvernoteAuth(ConsumerBasedOAuth):
     SETTINGS_KEY_NAME = 'EVERNOTE_CONSUMER_KEY'
     SETTINGS_SECRET_NAME = 'EVERNOTE_CONSUMER_SECRET'
 
-    def user_data(self, access_token, *args, **kwargs):
-        """Return user data provided"""
-        return access_token.user_info
-
     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)
         params = parse_qs(response)
 
-        # evernote sents a empty secret token, this way it doesn't fires up the
-        # exception
+        # evernote sents a empty secret token, this way it doesn't fires up the exception
         response = response.replace("oauth_token_secret=", "oauth_token_secret=None")
         token = Token.from_string(response)
 
         token.user_info = params
         return token
 
+    def user_data(self, access_token, *args, **kwargs):
+        """Return user data provided
+        {'edam_expires': ['1367525289541'],
+         'edam_noteStoreUrl': ['https://sandbox.evernote.com/shard/s1/notestore'],
+         'edam_shard': ['s1'],
+         'edam_userId': ['123841'],
+         'edam_webApiUrlPrefix': ['https://sandbox.evernote.com/shard/s1/'],
+         'oauth_token': ['S=s1:U=1e3c1:E=13e66dbee45:C=1370f2ac245:P=185:A=my_user:H=411443c5e8b20f8718ed382a19d4ae38']}
+        """
+        return access_token.user_info
+
 # Backend definition
 BACKENDS = {
     'evernote': EvernoteAuth,