]> git.parisson.com Git - django-social-auth.git/commitdiff
Flexible arguments on user_data() method. Refs #313.
authorMatías Aguirre <matiasaguirre@gmail.com>
Fri, 13 Apr 2012 23:35:16 +0000 (20:35 -0300)
committerMatías Aguirre <matiasaguirre@gmail.com>
Fri, 13 Apr 2012 23:35:16 +0000 (20:35 -0300)
13 files changed:
social_auth/backends/__init__.py
social_auth/backends/contrib/dropbox.py
social_auth/backends/contrib/fitbit.py
social_auth/backends/contrib/flickr.py
social_auth/backends/contrib/foursquare.py
social_auth/backends/contrib/github.py
social_auth/backends/contrib/instagram.py
social_auth/backends/contrib/linkedin.py
social_auth/backends/contrib/orkut.py
social_auth/backends/contrib/vkontakte.py
social_auth/backends/facebook.py
social_auth/backends/google.py
social_auth/backends/twitter.py

index bf7767dba81e18f75ed2de1d3369963d2a653f2c..48f6320dac6daafd44dd6f9f489736151da99b71 100644 (file)
@@ -616,7 +616,7 @@ class ConsumerBasedOAuth(BaseOAuth):
         request = self.oauth_request(token, self.ACCESS_TOKEN_URL)
         return Token.from_string(self.fetch_response(request))
 
-    def user_data(self, access_token):
+    def user_data(self, access_token, *args, **kwargs):
         """Loads user data from service"""
         raise NotImplementedError('Implement in subclass')
 
@@ -698,16 +698,8 @@ class BaseOAuth2(BaseOAuth):
             error = response.get('error_description') or response.get('error')
             raise AuthFailed(self, error)
         else:
-            try:
-                argnum = self.user_data.im_func.func_code.co_argcount
-            except AttributeError:
-                argnum = 2
-            finally:
-                user_data_args = [response['access_token']]
-                if argnum == 3:
-                    user_data_args.append(response)
-            
-            response.update(self.user_data(*user_data_args) or {})
+            data = self.user_data(response['access_token'], response)
+            response.update(data or {})
             kwargs.update({
                 'auth': self,
                 'response': response,
index 2e4a9cd0ff6b356bdb946beca31f57e264ded9c9..abdf6ce1d27aeff1fbe280d6627235cd0913ca80 100644 (file)
@@ -53,7 +53,7 @@ class DropboxAuth(ConsumerBasedOAuth):
     SETTINGS_KEY_NAME = 'DROPBOX_APP_ID'
     SETTINGS_SECRET_NAME = 'DROPBOX_API_SECRET'
 
-    def user_data(self, access_token):
+    def user_data(self, access_token, *args, **kwargs):
         """Loads user data from service"""
         url = 'https://' + DROPBOX_API + '/1/account/info'
         request = self.oauth_request(access_token, url)
index 4c7539c8210042528a165659eb890a3a7cf49745..b60d6b3fec316811fe9d3d5203a0a22ee8ffab80 100644 (file)
@@ -72,7 +72,7 @@ class FitbitAuth(ConsumerBasedOAuth):
                                                else None
         return token
 
-    def user_data(self, access_token):
+    def user_data(self, access_token, *args, **kwargs):
         """Loads user data from service"""
         return {
             'id': access_token.user_nsid,
index 9d4e4676b4fec430a158345ae6576fa784c4dd39..4487d587dd3a0b72e2cf6ab5bde72c896442fe6b 100644 (file)
@@ -73,7 +73,7 @@ class FlickrAuth(ConsumerBasedOAuth):
                                                else None
         return token
 
-    def user_data(self, access_token):
+    def user_data(self, access_token, *args, **kwargs):
         """Loads user data from service"""
         return {
             'id': access_token.user_nsid,
index 369bd6ba1d55c87a0aa48ae43eab1a241fb6d706..23409cbac21d3dac93b9dd1715707c1395d2f29d 100644 (file)
@@ -38,7 +38,7 @@ class FoursquareAuth(BaseOAuth2):
     SETTINGS_KEY_NAME = 'FOURSQUARE_CONSUMER_KEY'
     SETTINGS_SECRET_NAME = 'FOURSQUARE_CONSUMER_SECRET'
 
-    def user_data(self, access_token):
+    def user_data(self, access_token, *args, **kwargs):
         """Loads user data from service"""
         params = {'oauth_token': access_token}
         url = FOURSQUARE_CHECK_AUTH + '?' + urllib.urlencode(params)
index bd0b96049a8a4e1e07fb8424e3c1deac57544a7b..84d65861622d6c759571ffb6a9b51d23be2d8973 100644 (file)
@@ -91,7 +91,7 @@ class GithubAuth(BaseOAuth):
         })
         return authenticate(*args, **kwargs)
 
-    def user_data(self, access_token):
+    def user_data(self, access_token, *args, **kwargs):
         """Loads user data from service"""
         url = GITHUB_USER_DATA_URL + urlencode({
             'access_token': access_token
index a40c0eeb7901c261cb5f47481e72b4afb0b5f414..faa2e82cb3264f59128724cce2168cda0ce53f56 100644 (file)
@@ -38,7 +38,7 @@ class InstagramAuth(BaseOAuth2):
     SETTINGS_KEY_NAME = 'INSTAGRAM_CLIENT_ID'
     SETTINGS_SECRET_NAME = 'INSTAGRAM_CLIENT_SECRET'
 
-    def user_data(self, access_token):
+    def user_data(self, access_token, *args, **kwargs):
         """Loads user data from service"""
         params = {'access_token': access_token}
         url = INSTAGRAM_CHECK_AUTH + '?' + urllib.urlencode(params)
index 910a0a291712a2f2d443420df8bb8dab1fc2da46..1e2a7f871e2b2c1f2ce69d8cb745cf81672b7975 100644 (file)
@@ -50,7 +50,7 @@ class LinkedinAuth(ConsumerBasedOAuth):
     SETTINGS_KEY_NAME = 'LINKEDIN_CONSUMER_KEY'
     SETTINGS_SECRET_NAME = 'LINKEDIN_CONSUMER_SECRET'
 
-    def user_data(self, access_token):
+    def user_data(self, access_token, *args, **kwargs):
         """Return user data provided"""
         fields_selectors = LINKEDIN_FIELD_SELECTORS + \
                            setting('LINKEDIN_EXTRA_FIELD_SELECTORS', [])
index c7ed4d2a424e7006a0222f7137138b99c8c81bab..c2397b2004811f06a3118b2e9b8b44812701386d 100644 (file)
@@ -51,7 +51,7 @@ class OrkutAuth(BaseGoogleOAuth):
     SETTINGS_KEY_NAME = 'ORKUT_CONSUMER_KEY'
     SETTINGS_SECRET_NAME = 'ORKUT_CONSUMER_SECRET'
 
-    def user_data(self, access_token):
+    def user_data(self, access_token, *args, **kwargs):
         """Loads user data from Orkut service"""
         fields = ORKUT_DEFAULT_DATA
         if setting('ORKUT_EXTRA_DATA'):
index baa8643b17990ac3ab4341dd61689195dc85f4fb..7026579f2bc04d7f35ea98960fa1780e3a74a080 100644 (file)
@@ -5,11 +5,9 @@ Vkontakte OAuth support.
 from urllib import urlencode, urlopen
 
 from django.utils import simplejson
-from django.contrib.auth import authenticate
 
 from social_auth.utils import setting
 from social_auth.backends import BaseOAuth2, OAuthBackend, USERNAME
-from social_auth.backends.exceptions import AuthFailed
 
 
 # Vkontakte configuration
@@ -26,7 +24,7 @@ class VkontakteBackend(OAuthBackend):
         ('id', 'id'),
         ('expires', setting('SOCIAL_AUTH_EXPIRATION', 'expires'))
     ]
-    
+
     def get_user_id(self, details, response):
         "OAuth providers return an unique user id in response"""
         return response['user_id']
@@ -34,7 +32,8 @@ class VkontakteBackend(OAuthBackend):
     def get_user_details(self, response):
         """Return user details from Vkontakte account"""
         print response
-        return {USERNAME: response.get('nickname') or response.get('screen_name') ,
+        return {USERNAME: response.get('nickname') or \
+                          response.get('screen_name'),
                 'email':  '',
                 'first_name': response.get('first_name'),
                 'last_name': response.get('last_name')}
@@ -48,8 +47,8 @@ class VkontakteAuth(BaseOAuth2):
     AUTH_BACKEND = VkontakteBackend
     SETTINGS_KEY_NAME = 'VK_APP_ID'
     SETTINGS_SECRET_NAME = 'VK_API_SECRET'
-    
-    def user_data(self, access_token, response):
+
+    def user_data(self, access_token, response, *args, **kwargs):
         """Loads user data from service"""
         params = {'access_token': access_token,
                   'fields': 'first_name,last_name,screen_name,nickname',
@@ -67,7 +66,6 @@ class VkontakteAuth(BaseOAuth2):
         return setting('VK_EXTRA_SCOPE', [])
 
 
-
 # Backend definition
 BACKENDS = {
     'vkontakte': VkontakteAuth,
index 0669340503c010b253133d081119aee20d16e679..ac7e56f08c271540048341fd5196be87aff6191e 100644 (file)
@@ -59,7 +59,7 @@ class FacebookAuth(BaseOAuth2):
     def get_scope(self):
         return setting('FACEBOOK_EXTENDED_PERMISSIONS', [])
 
-    def user_data(self, access_token):
+    def user_data(self, access_token, *args, **kwargs):
         """Loads user data from service"""
         data = None
         params = setting('FACEBOOK_PROFILE_EXTRA_PARAMS', {})
index 2e0ccb6db755ee33ee6647921c6a0e0256ab4fee..e7d76ab8c1fcbbbc4d63788ab4dba71882ceea22 100644 (file)
@@ -115,7 +115,7 @@ class BaseGoogleOAuth(ConsumerBasedOAuth):
     ACCESS_TOKEN_URL = ACCESS_TOKEN_URL
     SERVER_URL = GOOGLE_OAUTH_SERVER
 
-    def user_data(self, access_token):
+    def user_data(self, access_token, *args, **kwargs):
         """Loads user data from G service"""
         raise NotImplementedError('Implement in subclass')
 
@@ -126,7 +126,7 @@ class GoogleOAuth(BaseGoogleOAuth):
     SETTINGS_KEY_NAME = 'GOOGLE_CONSUMER_KEY'
     SETTINGS_SECRET_NAME = 'GOOGLE_CONSUMER_SECRET'
 
-    def user_data(self, access_token):
+    def user_data(self, access_token, *args, **kwargs):
         """Return user data from Google API"""
         request = self.oauth_request(access_token, GOOGLEAPIS_EMAIL,
                                      {'alt': 'json'})
@@ -188,7 +188,7 @@ class GoogleOAuth2(BaseOAuth2):
     def get_scope(self):
         return GOOGLE_OAUTH2_SCOPE + setting('GOOGLE_OAUTH_EXTRA_SCOPE', [])
 
-    def user_data(self, access_token):
+    def user_data(self, access_token, *args, **kwargs):
         """Return user data from Google API"""
         return googleapis_profile(GOOGLEAPIS_PROFILE, access_token)
 
index 9df1d1736f2081fa7600532523c80dc26faf6276..d685017652c5ae96a026ecd054659211af664e57 100644 (file)
@@ -70,7 +70,7 @@ class TwitterAuth(ConsumerBasedOAuth):
     SETTINGS_KEY_NAME = 'TWITTER_CONSUMER_KEY'
     SETTINGS_SECRET_NAME = 'TWITTER_CONSUMER_SECRET'
 
-    def user_data(self, access_token):
+    def user_data(self, access_token, *args, **kwargs):
         """Return user data provided"""
         request = self.oauth_request(access_token, TWITTER_CHECK_AUTH)
         json = self.fetch_response(request)