From 8f8b560d7fd4a93347134bd3f0e9d62155d30172 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Mat=C3=ADas=20Aguirre?= Date: Thu, 3 May 2012 21:04:10 -0300 Subject: [PATCH] Simplify get_scope() code. Apply scope vars changes to live backend. Refs #340 --- social_auth/backends/__init__.py | 11 ++++------- social_auth/backends/contrib/live.py | 6 ++---- social_auth/backends/google.py | 2 +- 3 files changed, 7 insertions(+), 12 deletions(-) diff --git a/social_auth/backends/__init__.py b/social_auth/backends/__init__.py index 10c733d..1923ef8 100644 --- a/social_auth/backends/__init__.py +++ b/social_auth/backends/__init__.py @@ -662,9 +662,8 @@ class BaseOAuth2(BaseOAuth): ACCESS_TOKEN_URL = None SCOPE_SEPARATOR = ' ' RESPONSE_TYPE = 'code' - SCOPE_VAR_NAME = None - DEFAULT_SCOPE = [] + DEFAULT_SCOPE = None def auth_url(self): """Return redirect url""" @@ -722,11 +721,9 @@ class BaseOAuth2(BaseOAuth): def get_scope(self): """Return list with needed access scope""" - scope_var_name = getattr(self, 'SCOPE_VAR_NAME', None) - scope = getattr(self, 'DEFAULT_SCOPE', []) - # scope_var_name should not be empty string - if scope_var_name: - scope = scope + setting(scope_var_name, []) + scope = self.DEFAULT_SCOPE or [] + if self.SCOPE_VAR_NAME: + scope += setting(self.SCOPE_VAR_NAME, []) return scope diff --git a/social_auth/backends/contrib/live.py b/social_auth/backends/contrib/live.py index 66a003f..6d68208 100644 --- a/social_auth/backends/contrib/live.py +++ b/social_auth/backends/contrib/live.py @@ -68,10 +68,8 @@ class LiveAuth(BaseOAuth2): SETTINGS_KEY_NAME = 'LIVE_CLIENT_ID' SETTINGS_SECRET_NAME = 'LIVE_CLIENT_SECRET' SCOPE_SEPARATOR = ',' - - def get_scope(self): - """Return list with needed access scope""" - return LIVE_DEFAULT_PERMISSIONS + setting('LIVE_EXTENDED_PERMISSIONS', []) + SCOPE_VAR_NAME = 'LIVE_EXTENDED_PERMISSIONS' + DEFAULT_SCOPE = LIVE_DEFAULT_PERMISSIONS def user_data(self, access_token, *args, **kwargs): """Loads user data from service""" diff --git a/social_auth/backends/google.py b/social_auth/backends/google.py index 6198bc2..b25f9eb 100644 --- a/social_auth/backends/google.py +++ b/social_auth/backends/google.py @@ -186,7 +186,7 @@ class GoogleOAuth2(BaseOAuth2): SETTINGS_SECRET_NAME = 'GOOGLE_OAUTH2_CLIENT_SECRET' SCOPE_VAR_NAME = 'GOOGLE_OAUTH_EXTRA_SCOPE' DEFAULT_SCOPE = GOOGLE_OAUTH2_SCOPE - + def user_data(self, access_token, *args, **kwargs): """Return user data from Google API""" return googleapis_profile(GOOGLEAPIS_PROFILE, access_token) -- 2.39.5