]> git.parisson.com Git - django-social-auth.git/commitdiff
Avoid refresh_token overwrite on further logins. Closes #299
authorMatías Aguirre <matiasaguirre@gmail.com>
Thu, 29 Mar 2012 21:11:30 +0000 (18:11 -0300)
committerMatías Aguirre <matiasaguirre@gmail.com>
Thu, 29 Mar 2012 21:11:30 +0000 (18:11 -0300)
README.rst
doc/backends/oauth.rst
doc/backends/openid.rst
social_auth/backends/__init__.py
social_auth/backends/google.py

index 9e14b063b1106775abc6b4231f8c7787d97e7a85..fd361c3db99651ac885b03ca721ce6670792a460 100644 (file)
@@ -614,7 +614,11 @@ Example::
     GOOGLE_AX_EXTRA_DATA = [(..., ...)]
 
 Settings must be a list of tuples mapping value name in response and value
-alias used to store.
+alias used to store. A third value (boolean) is supported to, it's purpose is
+to signal if the value should be discarded if it evaluates to ``False``, this
+is to avoid replacing old (needed) values when they don't form part of current
+response. If not present, then this check is avoided and the value will replace
+any data.
 
 OAuth
 ^^^^^
@@ -639,7 +643,12 @@ Example::
     FACEBOOK_EXTRA_DATA = [(..., ...)]
 
 Settings must be a list of tuples mapping value name in response and value
-alias used to store.
+alias used to store. A third value (boolean) is supported to, it's purpose is
+to signal if the value should be discarded if it evaluates to ``False``, this
+is to avoid replacing old (needed) values when they don't form part of current
+response. If not present, then this check is avoided and the value will replace
+any data.
+
 
 Twitter
 ^^^^^^^
index f05b921fccaaa2eadd639a45bcccadf05475c215..56d0c5de86d67e34e31a102b759b3b9633e39504 100644 (file)
@@ -21,7 +21,11 @@ Example::
     FACEBOOK_EXTRA_DATA = [(..., ...)]
 
 Settings must be a list of tuples mapping value name in response and value
-alias used to store.
+alias used to store. A third value (boolean) is supported to, it's purpose is
+to signal if the value should be discarded if it evaluates to ``False``, this
+is to avoid replacing old (needed) values when they don't form part of current
+response. If not present, then this check is avoided and the value will replace
+any data.
 
 
 .. _OAuth: http://oauth.net/
index 2b8cd591af030ac49cc29fd7a3c3d19b6893682d..98d00077aab9262854caabdab0b810070a4d601a 100644 (file)
@@ -22,7 +22,11 @@ Example::
     GOOGLE_AX_EXTRA_DATA = [(..., ...)]
 
 Settings must be a list of tuples mapping value name in response and value
-alias used to store.
+alias used to store. A third value (boolean) is supported to, it's purpose is
+to signal if the value should be discarded if it evaluates to ``False``, this
+is to avoid replacing old (needed) values when they don't form part of current
+response. If not present, then this check is avoided and the value will replace
+any data.
 
 .. _OpenId: http://openid.net/
 .. _OAuth: http://oauth.net/
index c38e60a12f7528ba68a832381a2c65917f88d5c4..10f597b0587592428c2f8b016c39da9c2899954b 100644 (file)
@@ -219,7 +219,20 @@ class OAuthBackend(SocialAuthBackend):
         data = {'access_token': response.get('access_token', '')}
         name = self.name.replace('-', '_').upper()
         names = (self.EXTRA_DATA or []) + setting(name + '_EXTRA_DATA', [])
-        data.update((alias, response.get(name)) for name, alias in names)
+        for entry in names:
+            if len(entry) == 2:
+                (name, alias), discard = entry, False
+            elif len(entry) == 3:
+                name, alias, discard = entry
+            elif len(entry) == 1:
+                name = alias = entry
+            else:  # ???
+                continue
+
+            value = response.get(name)
+            if discard and not value:
+                continue
+            data[alias] = value
         return data
 
 
index d808e8a08ff336c6af3a4e5e82cd16deda7e04f3..2e0ccb6db755ee33ee6647921c6a0e0256ab4fee 100644 (file)
@@ -70,7 +70,7 @@ class GoogleOAuth2Backend(GoogleOAuthBackend):
     """Google OAuth2 authentication backend"""
     name = 'google-oauth2'
     EXTRA_DATA = [
-        ('refresh_token', 'refresh_token'),
+        ('refresh_token', 'refresh_token', True),
         ('expires_in', setting('SOCIAL_AUTH_EXPIRATION', 'expires'))
     ]