Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Override get_user() in SocialAuthBackend so it supports returning use…

…rs from a custom user model
  • Loading branch information...
commit cca9ad912bb15e49e06ad57f784d9b476be26d59 1 parent 6cc074f
Steven Van Bael vbsteven authored

Showing 1 changed file with 13 additions and 0 deletions. Show diff stats Hide diff stats

  1. +13 0 social_auth/backends/__init__.py
13 social_auth/backends/__init__.py
@@ -26,6 +26,7 @@
26 26 from oauth2 import Consumer as OAuthConsumer, Token, Request as OAuthRequest, \
27 27 SignatureMethod_HMAC_SHA1
28 28
  29 +from django.db import models
29 30 from django.conf import settings
30 31 from django.contrib.auth import authenticate
31 32 from django.contrib.auth.backends import ModelBackend
@@ -38,6 +39,12 @@
38 39 from social_auth.backends.exceptions import StopPipeline
39 40
40 41
  42 +if getattr(settings, 'SOCIAL_AUTH_USER_MODEL', None):
  43 + User = models.get_model(*settings.SOCIAL_AUTH_USER_MODEL.rsplit('.', 1))
  44 +else:
  45 + from django.contrib.auth.models import User
  46 +
  47 +
41 48 # OpenID configuration
42 49 OLD_AX_ATTRS = [
43 50 ('http://schema.openid.net/contact/email', 'old_email'),
@@ -156,6 +163,12 @@ def get_user_details(self, response):
156 163 """
157 164 raise NotImplementedError('Implement in subclass')
158 165
  166 + def get_user(self, user_id):
  167 + """Return user with given ID from the User model used by this backend"""
  168 + try:
  169 + return User.objects.get(pk=user_id)
  170 + except User.DoesNotExist:
  171 + return None
159 172
160 173 class OAuthBackend(SocialAuthBackend):
161 174 """OAuth authentication backend base class.

0 comments on commit cca9ad9

Please sign in to comment.
Something went wrong with that request. Please try again.