James
James

Reputation: 53

Django All-Auth Facebook Integration

I am having problems setting up the Facebook social integration for Django All-Auth. I have successfully setup the Google login, so I am at a loss as to why one works and the other doesn't. I think it might be due to my Facebook configuration in settings.py, as Facebook has many possible options.

Events Summary:

Any idea how I can diagnose what exactly is causing the problem?

Example webhost message:

[16/Nov/2016 02:14:37] "GET /accounts/facebook/login/callback/?code=AQArXlYq-4K8
UBnuACFQZK39HvVAkZzYpnkP4hI223Y5kA1JmmjdF5yOeVHnrDRpxMOPFNviDzYeSSBvWccALZHGTl-8
7_A1-jtwpDF0UdgoGSVVd9KsrGrQDrHi0i6X9l_pO76-_Ro0N8ePr4L7uUd2G3aWAlZVtAKNNPG1kNBf
OIwhb_RFRJrFvdLA5TlUXaGFdkEsRdMawyG8tdAstXdm5FcxKBRYMOE98j3yalHm5oLLeXOMKJ14EdDw
8-DHU6f5Ze1DWaWWUd-3MFP-NvF2sG4XbA6n5McPrLgYZKb_YG8Slqgo5GDVrKHT1tNedzgceCjjDXT3
TfbzZc9e-aQT9EycKAdGDr1TkKw9lO-Lqw&state=5WqSSFEKy5bc HTTP/1.1" 200 8243

Example URL after return from Facebook:

http://127.0.0.1:8000/accounts/facebook/login/callback/?code=AQArXlYq-4K8UBnuACFQZK39HvVAkZzYpnkP4hI223Y5kA1JmmjdF5yOeVHnrDRpxMOPFNviDzYeSSBvWccALZHGTl-87_A1-jtwpDF0UdgoGSVVd9KsrGrQDrHi0i6X9l_pO76-_Ro0N8ePr4L7uUd2G3aWAlZVtAKNNPG1kNBfOIwhb_RFRJrFvdLA5TlUXaGFdkEsRdMawyG8tdAstXdm5FcxKBRYMOE98j3yalHm5oLLeXOMKJ14EdDw8-DHU6f5Ze1DWaWWUd-3MFP-NvF2sG4XbA6n5McPrLgYZKb_YG8Slqgo5GDVrKHT1tNedzgceCjjDXT3TfbzZc9e-aQT9EycKAdGDr1TkKw9lO-Lqw&state=5WqSSFEKy5bc#_=_

Facebook Valid OAuth redirect URI:

Facebook Settings:

Admin Settings:

Settings.py Apps:

INSTALLED_APPS = [
    'home',

    # Django Standard Apps
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',

    # Django Crispy forms
    'crispy_forms',

    # Django allauth
    'django.contrib.sites',
    'allauth',
    'allauth.account',
    'allauth.socialaccount',
    'allauth.socialaccount.providers.facebook',
    'allauth.socialaccount.providers.google',
]

Settings.py Social:

SOCIALACCOUNT_PROVIDERS = \
    {
    'facebook':
    {'METHOD': 'oauth2',
    'SCOPE': ['email', 'public_profile'],
    'AUTH_PARAMS': {'auth_type': 'reauthenticate'},
    #'FIELDS': [
    #'id',
    #'email',
    #'name',
    #'first_name',
    #'last_name',
    #'verified',
    #'locale',
    #'timezone',
    #'link',
    #'gender',
    #'updated_time'],
    'EXCHANGE_TOKEN': True,
    #'LOCALE_FUNC': 'path.to.callable',
    'VERIFIED_EMAIL': False,
    'VERSION': 'v2.4'},

    'google':
    { 'SCOPE': ['profile', 'email'],
    'AUTH_PARAMS': { 'access_type': 'online' } }
    }

I uploaded this configuration with different redirect URIs to a test server with SSL and still have the same problem. Any ideas how I can fix this?

I am running Python 3.5.2, and the latest pip install for all-auth.

Thanks Stephen

Upvotes: 1

Views: 3056

Answers (1)

Andrew E
Andrew E

Reputation: 8327

I was just fighting this for a while.

The trick for me was that the Django-allauth "client" code needs to be the Facebook "appid", not the Facebook "client".

When I changed the Facebook "client" to the appid using the Django admin area (or you could edit the database), problem solved.

Upvotes: 1

Related Questions