RodrC
RodrC

Reputation: 69

Backend not Found for Facebook

I cant seem to get it to work guys, after reading similar questions my issue is not due to not specifying key and secret nor is it because i forgot to add '-oauth2' after facebook. please help??

All i see on the browser is Backend not Found. Maybe it is just because my django or python versions are too new?? I use python 3.6 and django 2.0...

here is my project's settings.py

SECRET_KEY = '<my_secret_key>'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True


# Application definition

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'main_app',
    'django_filters',
    'cuentas',
    'social_django',
]

MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
    'social_django.middleware.SocialAuthExceptionMiddleware',
]

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
                'social_django.context_processors.backends',
                'social_django.context_processors.login_redirect',
            ],
        },
    },
]

# python social auth settings
SOCIAL_AUTH_FACEBOOK_KEY = '<facebook_app_id>'

SOCIAL_AUTH_FACEBOOK_SECRET = '<facebook_app_secret>'

SOCIAL_AUTH_FACEBOOK_SCOPE = ['email']

SOCIAL_AUTH_FACEBOOK_API_VERSION = '2.11'

AUTHENTICATION_BACKENDS = [
    'social_core.backends.facebook.FacebookAppOAuth2',
    'social_core.backends.facebook.FacebookOAuth2',
    'django.contrib.auth.backends.ModelBackend',
]

SOCIAL_AUTH_URL_NAMESPACE = 'social'

SOCIAL_AUTH_PIPELINE = (
    'social_core.pipeline.social_auth.social_details',
    'social_core.pipeline.social_auth.social_uid',
    'social_core.pipeline.social_auth.social_user',
    'social_core.pipeline.user.get_username',
    'social_core.pipeline.user.create_user',
    'social_core.pipeline.social_auth.associate_user',
    'social_core.pipeline.social_auth.load_extra_data',
    'social_core.pipeline.user.user_details',
    'social_core.pipeline.social_auth.associate_by_email',
)

update... here is my main app's urls.py

from django.contrib import admin
from django.urls import path, include
from django.conf import settings
from django.conf.urls.static import static

urlpatterns = [
    path('', include('social_django.urls', namespace='social')),
    path('admin/', admin.site.urls),
    path('', include('main_app.urls') ),
    path('cuentas/', include('cuentas.urls')),
]

if settings.DEBUG is True:
    urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

and here is the login with facebook html link

<a href="{% url 'social:begin' 'facebook-oauth2' %}">Facebook</a>

I have just now added configurations in settings.py to output some more logging information so here is the output when i try to log in with facebook

Performing system checks..
System check identified no issues (0 silenced).
January 12, 2018 - 11:23:23
Django version 2.0, using settings 'jaguamigos.settings'
Starting development server at http://127.0.0.1:80/
Quit the server with CTRL-BREAK.
Not Found: /favicon.ico
Not Found: /favicon.ico
Not Found: /login/facebook-oauth2/
Not Found: /login/facebook-oauth2/

Upvotes: 1

Views: 878

Answers (2)

RodrC
RodrC

Reputation: 69

omab is absolutly right, inserting the name attribute for the facebook backend did the trick.

# Use 'facebook' instead of 'facebook-oauth2'
{% url 'social:begin' 'facebook' %}

Upvotes: 3

Mayank Jain
Mayank Jain

Reputation: 466

You can try this insted

<a href="{% url 'social:begin' 'facebook' %}">Login with Facebook</a>

and

AUTHENTICATION_BACKENDS = [
'social_core.backends.facebook.FacebookOAuth2',
'django.contrib.auth.backends.ModelBackend',
]

remove the FacebookAppOAuth2.

Upvotes: 2

Related Questions