]> git.parisson.com Git - django-social-auth.git/commitdiff
PEP8
authorMatías Aguirre <matiasaguirre@gmail.com>
Mon, 6 Feb 2012 18:49:58 +0000 (16:49 -0200)
committerMatías Aguirre <matiasaguirre@gmail.com>
Mon, 6 Feb 2012 18:49:58 +0000 (16:49 -0200)
social_auth/backends/google.py

index 0daf57dc10b0f26452ada85a5427fe58049b0f70..6a94cc0e574f40b0000d96d5c2188f3828e0e90c 100644 (file)
@@ -30,9 +30,9 @@ from social_auth.backends import OpenIdAuth, ConsumerBasedOAuth, BaseOAuth2, \
 
 # Google OAuth base configuration
 GOOGLE_OAUTH_SERVER = 'www.google.com'
-GOOGLE_OAUTH_AUTHORIZATION_URL = 'https://www.google.com/accounts/OAuthAuthorizeToken'
-GOOGLE_OAUTH_REQUEST_TOKEN_URL = 'https://www.google.com/accounts/OAuthGetRequestToken'
-GOOGLE_OAUTH_ACCESS_TOKEN_URL = 'https://www.google.com/accounts/OAuthGetAccessToken'
+AUTHORIZATION_URL = 'https://www.google.com/accounts/OAuthAuthorizeToken'
+REQUEST_TOKEN_URL = 'https://www.google.com/accounts/OAuthGetRequestToken'
+ACCESS_TOKEN_URL = 'https://www.google.com/accounts/OAuthGetAccessToken'
 
 # Google OAuth2 base configuration
 GOOGLE_OAUTH2_SERVER = 'accounts.google.com'
@@ -45,9 +45,6 @@ GOOGLEAPIS_EMAIL = 'https://www.googleapis.com/userinfo/email'
 GOOGLE_OPENID_URL = 'https://www.google.com/accounts/o8/id'
 
 
-# white-listed domains (else accept all)
-GOOGLE_WHITE_LISTED_DOMAINS = getattr(settings, 'GOOGLE_WHITE_LISTED_DOMAINS', [])
-
 # Backends
 class GoogleOAuthBackend(OAuthBackend):
     """Google OAuth authentication backend"""
@@ -81,12 +78,15 @@ class GoogleBackend(OpenIDBackend):
     name = 'google'
 
     def get_user_id(self, details, response):
-        """Return user unique id provided by service. For google user email
+        """
+        Return user unique id provided by service. For google user email
         is unique enought to flag a single user. Email comes from schema:
-        http://axschema.org/contact/email"""
-        # only include white-listed domains
-        if GOOGLE_WHITE_LISTED_DOMAINS and details['email'].split('@')[1] not in GOOGLE_WHITE_LISTED_DOMAINS: 
-            raise ValueError('INVALID DOMAIN')
+        http://axschema.org/contact/email
+        """
+        # White listed domains (accepts all if list is empty)
+        domains = setting('GOOGLE_WHITE_LISTED_DOMAINS', [])
+        if domains and details['email'].split('@', 1)[1] not in domains:
+            raise ValueError('Domain not allowed')
 
         return details['email']
 
@@ -103,9 +103,9 @@ class GoogleAuth(OpenIdAuth):
 
 class BaseGoogleOAuth(ConsumerBasedOAuth):
     """Base class for Google OAuth mechanism"""
-    AUTHORIZATION_URL = GOOGLE_OAUTH_AUTHORIZATION_URL
-    REQUEST_TOKEN_URL = GOOGLE_OAUTH_REQUEST_TOKEN_URL
-    ACCESS_TOKEN_URL = GOOGLE_OAUTH_ACCESS_TOKEN_URL
+    AUTHORIZATION_URL = AUTHORIZATION_URL
+    REQUEST_TOKEN_URL = REQUEST_TOKEN_URL
+    ACCESS_TOKEN_URL = ACCESS_TOKEN_URL
     SERVER_URL = GOOGLE_OAUTH_SERVER
 
     def user_data(self, access_token):