Django All-Auth Facebook集成 [英] Django All-Auth Facebook Integration
问题描述
我在为Django All-Auth设置Facebook社交集成时遇到问题。我已经成功设置了Google登录名,所以我茫然地知道为什么一个有效而另一个无效。我认为这可能是由于我在settings.py中配置了Facebook,因为Facebook有许多可能的选项。
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.
事件摘要:
- 在我的网站上单击通过Facebook登录按钮
- 浏览器重定向到Facebook网站进行登录,Facebook要求输入密码
- Facebook接受密码
- 浏览器重定向回我的网站,但显示以下错误:社交网络登录失败,尝试时发生错误即可通过您的社交网络帐户登录。
- 登录失败
- Click Login by Facebook Button on my website
- Browser redirects to Facebook website for login, and facebook requests password.
- Facebook accepts the password
- Browser redirects back to my website but gives the following error: "Social Network Login Failure, An error occurred while attempting to login via your social network account."
- Login failed
任何想法我都可以诊断到底是什么原因造成的?
Any idea how I can diagnose what exactly is causing the problem?
示例网络托管消息:
[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
从Facebook返回后的示例URL:
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有效的OAuth重定向URI:
- http://127.0.0.1:8000/accounts/facebook/login/callback/
Facebook设置:
- 客户端OAuth登录-已启用
- Web OAuth登录-启用
- 嵌入式浏览器OAuth登录-启用
管理员设置:
- 客户端ID,秘密ID输入
- 站点1设置为本地主机
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社交:
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' } }
}
我将具有不同重定向URI的此配置上传到具有SSL和仍然有同样的问题。有什么想法可以解决这个问题吗?
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?
我正在运行Python 3.5.2,并且安装了最新的pip进行全认证。
I am running Python 3.5.2, and the latest pip install for all-auth.
感谢
Stephen
Thanks Stephen
推荐答案
我只是在战斗了一段时间。
I was just fighting this for a while.
对我来说,诀窍是Django-allauth客户端代码必须是Facebook appid,而不是不是 Facebook客户端。
The trick for me was that the Django-allauth "client" code needs to be the Facebook "appid", not the Facebook "client".
当我使用Django管理区域将Facebook客户端更改为appid时(或者您可以编辑数据库),问题解决了。
When I changed the Facebook "client" to the appid using the Django admin area (or you could edit the database), problem solved.
这篇关于Django All-Auth Facebook集成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!