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
^^^^^
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
^^^^^^^
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/
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/
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
"""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'))
]