omab/django-social-auth — Issue #180: get_user() not working when using custom user model
Author: vbsteven
Created: 2011-11-17 21:04:38+00:00
State: open

I'm hacking around with django-social-auth and a custom user model and had the following issue.

I have my custom user model defined in SOCIAL_AUTH_USER_MODEL. When logging in with Google openid for example, everything works fine, I can associate the socialauth user with my custom user model and its ID gets saved in the session.

Now on the next request, when the session/auth middelwares kick in, it finds the correct ID and backend from the session and calls get_user(request, user_id) to get the user. It looks like get_user() is not overridden in SocialAuthBackend so the default (from ModelBackend) is taken. This default one is hardwared to use the django.contrib.auth User model.

Does it make sense to override get_user() in SocialAuthBackend so it takes into account the custom user model? I tried it with a quick hack (overriding and hardcoding to my user model) and it seems to be logging in the correct user now.

#my quick hack in SocialAuthBackend
def get_user(self, user_id):
try:
return EndUser.objects.get(pk=user_id)
except EndUser.DoesNotExist:
return None