From 78b59af49fae580dd011543ab64c1b99b6d43b2d Mon Sep 17 00:00:00 2001 From: Marc Hoersken Date: Sun, 20 May 2012 13:31:09 +0200 Subject: [PATCH] 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. --- social_auth/backends/google.py | 7 +++++++ 1 file changed, 7 insertions(+) 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], -- 2.39.5