Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"Backend not found" django social auth

Tags:

python

django

When I'm trying process social authorization with Google or Facebook, I get this error without trace for both socials.

Backend not found

Someone can find an mistake in social_django settings?

settings

INSTALLED_APPS = [
    ...
    'social_django',
    ...
]

MIDDLEWARE_CLASSES = [
    ...
    'social_django.middleware.SocialAuthExceptionMiddleware'
]

TEMPLATES = [
    {
     ...
        'OPTIONS': {
            'context_processors': [
                ...
                'social_django.context_processors.backends',
                'social_django.context_processors.login_redirect',
            ],
        },
    },
]
AUTHENTICATON_BACKENDS = (
    'social_core.backends.facebook.FacebookOAuth2',
    'social_core.backends.google.GoogleOAuth2',
    'users.backends.AuthBackend',
)
SOCIAL_AUTH_URL_NAMESPACE = 'social'

SOCIAL_AUTH_FACEBOOK_KEY = '...'
SOCIAL_AUTH_FACEBOOK_SECRET = '...'

SOCIAL_AUTH_GOOGLE_OAUTH2_KEY ='...'
SOCIAL_AUTH_GOOGLE_OAUTH2_SECRET = '...'

urls.py

urlpatterns = [
    url('', include('social_django.urls', namespace='social')),
    ...
]

template

<a href="{% url 'social:begin' backend='google-oauth2' %}">FB</a>
<a href="{% url 'social:begin' backend='facebook' %}">GOOGLE</a

users.backend.AuthBackend

from django.db.models import Q
from django.contrib.auth.backends import ModelBackend

from users.models import User


class AuthBackend(ModelBackend):
    supports_object_permissions = True
    supports_anonymous_user = False
    supports_inactive_user = False

    def authenticate(self, username, password):
        try:
            user = User.objects.filter(is_active=True).get(Q(email=username) | Q(phone_number=username))
        except User.DoesNotExist:
            return None
        return user if user.check_password(password) else None
like image 310
Anton Makushchenko Avatar asked Dec 18 '22 01:12

Anton Makushchenko


1 Answers

You need to add 'django.contrib.auth.backends.ModelBackend', in AUTHENTICATON_BACKENDS.

AUTHENTICATION_BACKENDS = (
    'django.contrib.auth.backends.ModelBackend',
    'social_core.backends.github.GithubOAuth2',
    'social_core.backends.twitter.TwitterOAuth',
    'social_core.backends.facebook.FacebookOAuth2',
    'social_core.backends.google.GoogleOAuth2',
)
like image 155
Astik Anand Avatar answered Dec 20 '22 17:12

Astik Anand