From: Marc Hoersken Date: Sun, 20 May 2012 11:31:09 +0000 (+0200) Subject: Added option to use the immutable identifier Google User ID X-Git-Url: https://git.parisson.com/?a=commitdiff_plain;h=78b59af49fae580dd011543ab64c1b99b6d43b2d;p=django-social-auth.git Added option to use the immutable identifier Google User ID Setting GOOGLE_OAUTH2_USE_UNIQUE_USER_ID to True for the Google OAuth 2.0 Backend makes use of the id fields in the returned Google profile information instead of the mutable email. --- diff --git a/social_auth/backends/google.py b/social_auth/backends/google.py index 3068ac6..01e8701 100644 --- a/social_auth/backends/google.py +++ b/social_auth/backends/google.py @@ -74,6 +74,13 @@ class GoogleOAuth2Backend(GoogleOAuthBackend): ('expires_in', setting('SOCIAL_AUTH_EXPIRATION', 'expires')) ] + def get_user_id(self, details, response): + """Use google email or id as unique id""" + user_id = super(GoogleOAuth2Backend, self).get_user_id(details, response) + if setting('GOOGLE_OAUTH2_USE_UNIQUE_USER_ID', False): + return response['id'] + return user_id + def get_user_details(self, response): email = response['email'] return {USERNAME: email.split('@', 1)[0],