]> git.parisson.com Git - django-social-auth.git/commitdiff
Throw exceptions if data-retrieval fails. Better comments
authorAndrew Korzhuev <wolfon@gmail.com>
Wed, 2 May 2012 22:07:48 +0000 (02:07 +0400)
committerAndrew Korzhuev <wolfon@gmail.com>
Wed, 2 May 2012 22:07:48 +0000 (02:07 +0400)
social_auth/backends/contrib/live.py
social_auth/backends/contrib/yahoo.py

index c3680be1fe7d3a344cfe2320d86b2238fd4b44c0..66a003f25aa1d8d984a9cdb7aed871c976762c50 100644 (file)
@@ -4,12 +4,15 @@ MSN Live Connect oAuth 2.0
 Settings:
 LIVE_CLIENT_ID
 LIVE_CLIENT_SECRET
-LIVE_EXTENDED_PERMISSIONS (default: wl.basic, wl.emails)
+LIVE_EXTENDED_PERMISSIONS (defaults are: wl.basic, wl.emails)
 
 References:
 * oAuth  http://msdn.microsoft.com/en-us/library/live/hh243649.aspx
 * Scopes http://msdn.microsoft.com/en-us/library/live/hh243646.aspx
 * REST   http://msdn.microsoft.com/en-us/library/live/hh243648.aspx
+
+Throws:
+AuthUnknownError - if user data retrieval fails
 """
 from urllib import urlencode, urlopen
 
@@ -17,6 +20,7 @@ from django.utils import simplejson
 
 from social_auth.utils import setting
 from social_auth.backends import BaseOAuth2, OAuthBackend, USERNAME
+from social_auth.backends.exceptions import AuthUnknownError
 
 
 # Live Connect configuration
@@ -24,7 +28,7 @@ LIVE_AUTHORIZATION_URL    = 'https://login.live.com/oauth20_authorize.srf'
 LIVE_ACCESS_TOKEN_URL     = 'https://login.live.com/oauth20_token.srf'
 LIVE_USER_DATA_URL        = 'https://apis.live.net/v5.0/me'
 LIVE_SERVER               = 'live.com'
-LIVE_EXTENDED_PERMISSIONS = ['wl.basic', 'wl.emails']
+LIVE_DEFAULT_PERMISSIONS  = ['wl.basic', 'wl.emails']
 
 
 class LiveBackend(OAuthBackend):
@@ -67,7 +71,7 @@ class LiveAuth(BaseOAuth2):
 
     def get_scope(self):
         """Return list with needed access scope"""
-        return setting('LIVE_EXTENDED_PERMISSIONS', LIVE_EXTENDED_PERMISSIONS)
+        return LIVE_DEFAULT_PERMISSIONS + setting('LIVE_EXTENDED_PERMISSIONS', [])
 
     def user_data(self, access_token, *args, **kwargs):
         """Loads user data from service"""
@@ -76,8 +80,8 @@ class LiveAuth(BaseOAuth2):
         })
         try:
             return simplejson.load(urlopen(url))
-        except ValueError:
-            return None
+        except (ValueError, IOError):
+            raise AuthUnknownError("Error during profile retrieval, please, try again later")
 
 
 # Backend definition
index e8905740178d1604a6d007bc389254a3a72c8af2..9ac234bbee099207bdd3f6502f139381b4a6b5df 100644 (file)
@@ -9,12 +9,20 @@ References:
 * http://developer.yahoo.com/oauth/guide/oauth-auth-flow.html
 * http://developer.yahoo.com/social/rest_api_guide/introspective-guid-resource.html
 * http://developer.yahoo.com/social/rest_api_guide/extended-profile-resource.html
+
+Scopes:
+To make this extension works correctly you have to have at least
+Yahoo Profile scope with Read permission
+
+Throws:
+AuthUnknownError - if user data retrieval fails (guid or profile)
 """
 
 from django.utils import simplejson
 
 from social_auth.utils import setting
 from social_auth.backends import ConsumerBasedOAuth, OAuthBackend, USERNAME
+from social_auth.backends.exceptions import AuthUnknownError
 
 
 # Google OAuth base configuration
@@ -38,7 +46,7 @@ class YahooOAuthBackend(OAuthBackend):
         return response['guid']
 
     def get_user_details(self, response):
-        """Return user details from Orkut account"""
+        """Return user details from Yahoo Profile"""
         fname = response.get('givenName')
         lname = response.get('familyName')
         return {USERNAME:     response.get('nickname'),
@@ -66,9 +74,13 @@ class YahooOAuth(ConsumerBasedOAuth):
         try:
             return simplejson.loads(response)['profile']
         except ValueError:
-            return None
+            raise AuthUnknownError("Error during profile retrieval, please, try again later")
 
     def _get_guid(self, access_token):
+        """
+            Beause you have to provide GUID for every API request
+            it's also returned during one of OAuth calls
+        """
         url = 'http://social.yahooapis.com/v1/me/guid?format=json'
         request = self.oauth_request(access_token, url)
         response = self.fetch_response(request)
@@ -76,7 +88,7 @@ class YahooOAuth(ConsumerBasedOAuth):
             json = simplejson.loads(response)
             return json['guid']['value']
         except ValueError:
-            return 'me'
+            raise AuthUnknownError("Error during user id retrieval, please, try again later")
 
 # Backend definition
 BACKENDS = {