How to solve django social auth error on Facebook?

Viewed 1940

I installed social-auth-app-django and followed the guide here to integrate Facebook login to django 1.8.18. The problem is when I go to "http://localhost:8000/social-auth/login/facebook/" I get below error

Can't Load URL: The domain of this URL isn't included in the app's domains. To be able to load this URL, add all domains and subdomains of your app to the App Domains field in your app settings.

Here is my settings.py file

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
import os

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
print (BASE_DIR)

SECRET_KEY = 'x220#z=kwd)kjiu#u+p$)v0lu+rspyosg+)l*k$ux9j)1h'
DEBUG = True

ALLOWED_HOSTS = ['localhost']    
INSTALLED_APPS = (
    ...
    'account',
    'social_django', #social classes
)

MIDDLEWARE_CLASSES = (
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
    'django.middleware.security.SecurityMiddleware',
     'social_django.middleware.SocialAuthExceptionMiddleware',
)

ROOT_URLCONF = 'bookmark.urls'

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [os.path.join(BASE_DIR, 'templates')],
        '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', # <--
            ],
        },
    },
]

WSGI_APPLICATION = 'bookmark.wsgi.application'

STATIC_URL = '/static/'
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR,'media/')
from django.core.urlresolvers import reverse_lazy
LOGIN_REDIRECT_URL = reverse_lazy('dashboard')
LOGIN_URL = reverse_lazy('login')
LOGOUT_URL = reverse_lazy('logout')

AUTHENTICATION_BACKENDS = (
    'social_core.backends.facebook.FacebookOAuth2',  #< --facebook

    'django.contrib.auth.backends.ModelBackend',
    'account.authentication.EmailAuthBackend',
)

SOCIAL_AUTH_FACEBOOK_KEY='1742581762468139'
SOCIAL_AUTH_FACEBOOK_SECRET='eae7dsfdsfdsf90b219becb84'

urls.py file

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

    urlpatterns = [
        url(r'^admin/', include(admin.site.urls)),
    url(r'^social-auth/',include('social_django.urls', namespace='social')), # <-- social facebook
        url(r'^account/',include('account.urls')),
        url(r'^$','account.views.dashboard',name="dashboard"),
    ]
    if settings.DEBUG:
        urlpatterns += static(settings.MEDIA_ROOT,
                              document_root=settings.MEDIA_ROOT)

Here is Facebook developer-app settings details screenshot enter image description here

I also changed localhost to something like "bookmarks.com" and changed it in /etc/hosts file but got same error error

2 Answers

Luckily I just stumbled upon this question. If you're still having issues with it try this: Go to your developer.facebook.com/apps when you're on the dashboard tab, you should see on the left hand side UI and at the bottom "Product". If you didn't already have your Facebook login app added, do so now. Moving on, once added click it, click "Settings" under "Facebook Login".

At this point you should see Client OAuth Settings, if you see "Use Strict Mode for Redirect URIs" as "yes" turn it off, but doing so you would need to add a "Valid OAuth redirect URIs" under that, just add localhost:8000 matching your top left hand side settings, "App domains, ie: localhost" and "URL Site, ie: localhost:8000/". That should do the trick! IF it doesn't please get back to me asap.

Related