0

I've been trying to get python-social-auth working and all I ever get is the error Client Error: Bad Request which totally doesn't help me debug the situation. In my research, I've come across some mention of a bug here but there are no real indications of how to resolve it. This question addresses it too, but again, points to the same GitHub thread with no real resolutions.

I can't seem to figure out what is going on. It seems that it's trying to complete the authentication process, but is failing at /complete/facebook/. Here's the trace:

Environment:


Request Method: GET
Request URL: http://23.239.3.97:8000/complete/facebook/?redirect_state=big_long_string_of_letters_and_numbers_i_removed_for_security

Django Version: 1.6.1
Python Version: 2.7.6
Installed Applications:
('django.contrib.admin',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'ms',
 'users',
 'south',
 'social.apps.django_app.default')
Installed Middleware:
('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')


Traceback:
File "/usr/lib/python2.7/dist-packages/django/core/handlers/base.py" in get_response
  112.                     response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/usr/lib/python2.7/dist-packages/django/views/decorators/csrf.py" in wrapped_view
  57.         return view_func(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/social/apps/django_app/utils.py" in wrapper
  52.             return func(request, backend, *args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/social/apps/django_app/views.py" in complete
  20.                        redirect_name=REDIRECT_FIELD_NAME, *args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/social/actions.py" in do_complete
  43.         user = backend.complete(user=user, *args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/social/backends/base.py" in complete
  40.         return self.auth_complete(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/social/backends/facebook.py" in auth_complete
  69.             'code': self.data['code']
File "/usr/local/lib/python2.7/dist-packages/social/backends/base.py" in get_querystring
  229.         return parse_qs(self.request(url, *args, **kwargs).text)
File "/usr/local/lib/python2.7/dist-packages/social/backends/base.py" in request
  222.         response.raise_for_status()
File "/usr/lib/python2.7/dist-packages/requests/models.py" in raise_for_status
  773.             raise HTTPError(http_error_msg, response=self)

Exception Type: HTTPError at /complete/facebook/
Exception Value: 400 Client Error: Bad Request

Here's the relevant settings.py info:

from django.conf.global_settings import TEMPLATE_CONTEXT_PROCESSORS
TEMPLATE_CONTEXT_PROCESSORS += (
    'social.apps.django_app.context_processors.backends',
    'social.apps.django_app.context_processors.login_redirect',
)

AUTHENTICATION_BACKENDS = (
    'social.backends.facebook.FacebookOAuth2',
    'django.contrib.auth.backends.ModelBackend',
)


SOCIAL_AUTH_FACEBOOK_KEY = '***'  #replaced actual with *** for security
SOCIAL_AUTH_FACEBOOK_SECRET = '***'  #replaced actual with *** for security

SOCIAL_AUTH_USERNAME_IS_FULL_EMAIL = True

LOGIN_REDIRECT_URL = '/'

SOCIAL_AUTH_LOGIN_URL = '/login/'
SOCIAL_AUTH_LOGIN_REDIRECT_URL = '/logged-in/'
SOCIAL_AUTH_LOGIN_ERROR_URL = '/login-error/'

SOCIAL_AUTH_FACEBOOK_SCOPE = ['email']

SOCIAL_AUTH_URL_NAMESPACE = 'social'

SOCIAL_AUTH_ADMIN_USER_SEARCH_FIELDS = ['username', 'email']

SOCIAL_AUTH_AUTHENTICATION_BACKENDS = (
  'social.backends.facebook',
)

SOUTH_MIGRATION_MODULES = {
  'default': 'social.apps.django_app.default.south_migrations',
}

The django dev server is returning a 500 error code, so it's something internal I'm guessing. I'm pulling my hair out on this one! Any ideas?

Community
  • 1
  • 1
Garfonzo
  • 3,876
  • 6
  • 43
  • 78

1 Answers1

0

I had a similar error when I failed to set the correct callback URL in the app settings in facebook. You have to indicate "http://www.yourdomain.com/login/facebook" callback url in the advanced settings of the app. Hope this helps.

Michael
  • 40
  • 4