]> git.parisson.com Git - django-social-auth.git/commitdiff
Added option to use the immutable identifier Google User ID
authorMarc Hoersken <info@marc-hoersken.de>
Sun, 20 May 2012 11:31:09 +0000 (13:31 +0200)
committerMarc Hoersken <info@marc-hoersken.de>
Sun, 20 May 2012 11:31:09 +0000 (13:31 +0200)
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

index 3068ac6291e9d3054cfbf935933750cf31af6b94..01e8701f08ff6ae65331e4f2ffe56cb01eab8d16 100644 (file)
@@ -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],