Search code examples
pythondjangofacebookpython-social-auth

How to implement facebook authentification with python social auth?


I followed this tutorial http://www.artandlogic.com/blog/2014/04/tutorial-adding-facebooktwittergoogle-authentication-to-a-django-application/ and I managed Google Auth to work but when I try to register as facebook user, 'http://localhost:8000/login/facebook' calls https://facebook.com/dialog/oauth which returns error 500 - internal server error.

This is what I set in my settings.py:

INSTALLED_APPS = (
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',

    'social.apps.django_app.default',

    ...
)


TEMPLATE_CONTEXT_PROCESSORS = (
   'django.contrib.auth.context_processors.auth',
   'django.core.context_processors.debug',
   'django.core.context_processors.i18n',
   'django.core.context_processors.media',
   'django.core.context_processors.static',
   'django.core.context_processors.tz',
   'django.contrib.messages.context_processors.messages',
   'social.apps.django_app.context_processors.backends',
   'social.apps.django_app.context_processors.login_redirect',
)

AUTHENTICATION_BACKENDS = (
   'social.backends.facebook.FacebookOAuth2',
   'social.backends.google.GoogleOAuth2',

   'django.contrib.auth.backends.ModelBackend',
)

SOCIAL_AUTH_FACEBOOK_KEY = 'xxxxxxxxxxxxxxx'
SOCIAL_AUTH_FACEBOOK_SECRET = 'xxxxxxxxxxxxxx'
SOCIAL_AUTH_FACEBOOK_SCOPE = ['email']
LOGIN_REDIRECT_URL = '/'

in urls.py

   url('', include('social.apps.django_app.urls', namespace='social')),
   url('', include('django.contrib.auth.urls', namespace='auth')),

and in https://developers.facebook.com/apps I created the new app, I added a new platform (website) which url I set to

http://localhost:8000

Is there something I forgot?


Solution

  • Try this

    You are trying to auth using your loaclhost:8000 web address. Which FB doesn't support localhost address. So change your local host address to define domain.

    Like

    domain.com:8000