Django Python Social Auth, Authentication Canceled by Facebook app

3.4k views Asked by At

I am trying to implement website login using Facebook credentials. I see different responses when I press Cancel on Facebook widget or Okay. When I press Cancel I see the following


    Environment:


    Request Method: GET
    Request URL: http://wakevent.com/complete/facebook/?redirect_state=cvZGNl42bKvgcDDDezBy14VJ1Eit5OmT&error=access_denied&error_code=200&error_description=Permissions+error&error_reason=user_denied&state=cvZGNl42bKvgcDDDezBy14VJ1Eit5OmT

    Django Version: 1.8.2
    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',
     'mainapp',
     '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.auth.middleware.SessionAuthenticationMiddleware',
     'django.contrib.messages.middleware.MessageMiddleware',
     'django.middleware.clickjacking.XFrameOptionsMiddleware',
     'django.middleware.security.SecurityMiddleware',
     'social.apps.django_app.middleware.SocialAuthExceptionMiddleware')


    Traceback:
    File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py" in get_response
      132.                     response = wrapped_callback(request, *callback_args, **callback_kwargs)
    File "/usr/local/lib/python2.7/dist-packages/django/views/decorators/cache.py" in _wrapped_view_func
      57.         response = view_func(request, *args, **kwargs)
    File "/usr/local/lib/python2.7/dist-packages/django/views/decorators/csrf.py" in wrapped_view
      58.         return view_func(*args, **kwargs)
    File "/usr/local/lib/python2.7/dist-packages/social/apps/django_app/utils.py" in wrapper
      51.             return func(request, backend, *args, **kwargs)
    File "/usr/local/lib/python2.7/dist-packages/social/apps/django_app/views.py" in complete
      28.                        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
      41.         return self.auth_complete(*args, **kwargs)
    File "/usr/local/lib/python2.7/dist-packages/social/utils.py" in wrapper
      229.             return func(*args, **kwargs)
    File "/usr/local/lib/python2.7/dist-packages/social/backends/facebook.py" in auth_complete
      68.         self.process_error(self.data)
    File "/usr/local/lib/python2.7/dist-packages/social/backends/facebook.py" in process_error
      60.         super(FacebookOAuth2, self).process_error(data)
    File "/usr/local/lib/python2.7/dist-packages/social/backends/oauth.py" in process_error
      363.                 raise AuthCanceled(self, data.get('error_description', ''))

    Exception Type: AuthCanceled at /complete/facebook/
    Exception Value: Authentication process canceled

Which is predicatble. But when I press Okay I see another error.


    Environment:


    Request Method: GET
    Request URL: http://wakevent.com/complete/facebook/?redirect_state=cvZGNl42bKvgcDDDezBy14VJ1Eit5OmT&code=AQBe5WWQYk9BJE2fvNIt0RWVYxLaddhXT6t3UQwtF3aJcvbbLrVwsMlxsKEgwulVAtV4WHlYG5lG1HbEHk_cjFhMfWEHy9B8dedrOZagw0AWyGVyvaFtRqOn8_3G8nQb2nEe-DZMdG13V7Jgzrebtu6QXxGuyNzZPVXRnbPiKGUz8jW2p-r_wWB7QAuW-6rdZuII8_1ePBBoGgzmLlKLvMLfZoCqI62h0slF5t2IoAraHahRtnkWeIeH6AVf5u4vzZ8qXatz9fuun8ZK-8rqv5p5HDWZOdydNGm7ZtNh0g1OSpZU4TFAGxAqWbo0LpgiCRs&state=cvZGNl42bKvgcDDDezBy14VJ1Eit5OmT

    Django Version: 1.8.2
    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',
     'mainapp',
     '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.auth.middleware.SessionAuthenticationMiddleware',
     'django.contrib.messages.middleware.MessageMiddleware',
     'django.middleware.clickjacking.XFrameOptionsMiddleware',
     'django.middleware.security.SecurityMiddleware',
     'social.apps.django_app.middleware.SocialAuthExceptionMiddleware')


    Traceback:
    File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py" in get_response
      132.                     response = wrapped_callback(request, *callback_args, **callback_kwargs)
    File "/usr/local/lib/python2.7/dist-packages/django/views/decorators/cache.py" in _wrapped_view_func
      57.         response = view_func(request, *args, **kwargs)
    File "/usr/local/lib/python2.7/dist-packages/django/views/decorators/csrf.py" in wrapped_view
      58.         return view_func(*args, **kwargs)
    File "/usr/local/lib/python2.7/dist-packages/social/apps/django_app/utils.py" in wrapper
      51.             return func(request, backend, *args, **kwargs)
    File "/usr/local/lib/python2.7/dist-packages/social/apps/django_app/views.py" in complete
      28.                        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
      41.         return self.auth_complete(*args, **kwargs)
    File "/usr/local/lib/python2.7/dist-packages/social/utils.py" in wrapper
      232.                 raise AuthCanceled(args[0])

    Exception Type: AuthCanceled at /complete/facebook/
    Exception Value: Authentication process canceled

I am running the website locally on Ubuntu 14.04 apache web server with 80 port. I suspect wrong Facebook app setup but do not know what to debug.

Also, I can mention that Twitter login is working on the same setup.

Please advise!

2

There are 2 answers

0
Artem On

I did wrong Facebook app setup. In the Security / Server IP Whitelist I put 127.0.0.1 address. The problem was gone after removing this address (blank space is okey).

0
Shubham Aggarwal On

Check the redirect URL. I had wrongly specified redirect URL along with client ID while making post request. For Facebook redirect URI is optional. Try removing that and it will work fine.