django social auth失败&;Facebook身份验证
我正在使用django social auth进行Facebook服务器端身份验证,我遇到了一个无法跟踪的错误:AuthFailed(“验证应用程序时出错”) 当我在本地测试并且Facebook应用程序站点URL指向localhost时,我没有收到此错误 但是,每次我将Facebook应用程序站点URL指向我的开发实例时,我都会遇到这个错误——例如 我无法找到可能导致AuthFailed(验证应用程序时出错)错误的原因列表 另外,我还没有找到其他人成功地使用django social auth并解决了这个问题 我在以下网站上找到了一些有用的信息:django social auth失败&;Facebook身份验证,django,facebook,facebook-authentication,django-socialauth,Django,Facebook,Facebook Authentication,Django Socialauth,我正在使用django social auth进行Facebook服务器端身份验证,我遇到了一个无法跟踪的错误:AuthFailed(“验证应用程序时出错”) 当我在本地测试并且Facebook应用程序站点URL指向localhost时,我没有收到此错误 但是,每次我将Facebook应用程序站点URL指向我的开发实例时,我都会遇到这个错误——例如 我无法找到可能导致AuthFailed(验证应用程序时出错)错误的原因列表 另外,我还没有找到其他人成功地使用django social auth并
最后,我想进行服务器端身份验证,因为我想检索用户名、电子邮件和照片。但是,如果可以通过客户端身份验证来实现,我想我可以试试 下面的代码 在settings.py中:
LOGIN_URL = '/account/login/'
LOGIN_REDIRECT_URL = '/'
LOGIN_ERROR_URL = '/account/login/' # added when trying to debug Facebook error
AUTHENTICATION_BACKENDS = (
'social_auth.backends.facebook.FacebookBackend',
'django.contrib.auth.backends.ModelBackend',
)
FACEBOOK_APP_ID = 'xxx'
FACEBOOK_API_SECRET = 'xxxxxx'
FACEBOOK_EXTENDED_PERMISSIONS = ['email']
SOCIAL_AUTH_CREATE_USERS = True
SOCIAL_AUTH_FORCE_RANDOM_USERNAME = False
SOCIAL_AUTH_DEFAULT_USERNAME = 'socialauth_user'
SOCIAL_AUTH_COMPLETE_URL_NAME = 'socialauth_complete'
SOCIAL_AUTH_ERROR_KEY = 'socialauth_error'
SOCIAL_AUTH_REDIRECT_IS_HTTPS = True # force https in dev and production
# is SOCIAL_AUTH_LOGIN_REDIRECT_URL or SOCIAL_AUTH_BACKEND_ERROR_URL needed???
SOCIAL_AUTH_PIPELINE = (
'social_auth.backends.pipeline.social.social_auth_user',
'social_auth.backends.pipeline.associate.associate_by_email',
'social_auth.backends.pipeline.misc.save_status_to_session',
'apps.dsa_pipeline.redirect_to_form',
'apps.dsa_pipeline.username',
'apps.dsa_pipeline.phone',
'social_auth.backends.pipeline.user.create_user',
'social_auth.backends.pipeline.social.associate_user',
'social_auth.backends.pipeline.social.load_extra_data',
'social_auth.backends.pipeline.user.update_user_details',
'apps.dsa_pipeline.profile',
)
在dsa_pipeline.py中:
from django.http import HttpResponseRedirect
from urllib2 import urlopen
def redirect_to_form(*args, **kwargs):
if not kwargs['request'].session.get('saved_username') and kwargs.get('user') is None:
return HttpResponseRedirect('/account/signup_dsa/')
def username(request, *args, **kwargs):
if kwargs.get('user'):
username = kwargs['user'].username
else:
username = request.session.get('saved_username')
return {'username': username}
def phone(request, *args, **kwargs):
if kwargs.get('phone'):
phone = kwargs['phone'].phone
else:
phone = request.session.get('saved_phone')
return {'phone': phone}
def profile(backend, details, response, social_user, uid, user, *args, **kwargs):
profile = user.profile
if not profile.phone:
ph = kwargs.get('phone')
if ph:
profile.phone = ph
profile.save()
在URL.py中:
urlpatterns = patterns("",
url(r"^$", direct_to_template, {"template": "homepage.html"}, name="home"),
url(r"^admin/", include(admin.site.urls)),
# profiles
url(r'^', include("apps.profiles.urls")),
url(r"^account/signup/$", SignupView.as_view(), name="account_signup"),
url(r"^account/signup_dsa/$", SignupViewDSA.as_view(), name="account_signup_dsa"),
url(r"^account/", include("account.urls")),
# Django Social Auth
url(r'', include('social_auth.urls')),
谢谢你的帮助 如果出现
authfiled
错误,我会检查上面几行使用的client\u id
、redirect\u uri
和client\u secret
的值,并与Facebook上的应用程序配置进行比较。查看回溯中变量“url”的值…'client_id'=设置中“FACEBOOK_应用程序_id”的值。“client_secret'=设置中“FACEBOOK_API_secret”的值重定向_uri'=。Facebook应用程序配置中的沙箱模式如何?顺便问一下,是什么条件导致AuthFailed错误?例如,如果我的域上的DNS查找与IP的反向查找不匹配,是否会发生此错误?我怀疑这与DNS有关,因为SSL和云主机的配置并不简单。