如何在Django中的localhost上运行Facebook身份验证?

时间:2019-04-29 12:20:45

标签: django django-facebook

我已在StackOverFlow上阅读了有关此问题的所有讨论,但它们似乎都已过时。

有人知道如何通过social-auth-app-django在Django中的localhost上运行facebook身份验证吗?  我大概花了一天左右的时间来解决它,但没有任何效果。

enter image description here

enter image description here


AUTHENTICATION_BACKENDS = (
    'social_core.backends.facebook.FacebookOAuth2',
    "social_core.backends.vk.VKOAuth2",
    "django.contrib.auth.backends.ModelBackend"
)
SOCIAL_AUTH_URL_NAMESPACE = 'social'

SOCIAL_AUTH_PIPELINE = (
    'social_core.pipeline.social_auth.social_details',
    'social_core.pipeline.social_auth.social_uid',
    'social_core.pipeline.social_auth.auth_allowed',
    'social_core.pipeline.social_auth.social_user',
    'social_core.pipeline.user.get_username',
    'social_core.pipeline.social_auth.associate_by_email',  
    'social_core.pipeline.user.create_user',
    'social_core.pipeline.social_auth.associate_user',
    'social_core.pipeline.social_auth.load_extra_data',
    'social_core.pipeline.user.user_details',
)
SOCIAL_AUTH_STRATEGY = 'social_django.strategy.DjangoStrategy'  # new
SOCIAL_AUTH_STORAGE = 'social_django.models.DjangoStorage'  # new


# facebook
#FACEBOOK_APP_ID = ' xxx'
#FACEBOOK_API_SECRET = ' xxx'
SOCIAL_AUTH_FACEBOOK_KEY = ' xxx'  # new
SOCIAL_AUTH_FACEBOOK_SECRET = 'xxx ' # new
SOCIAL_AUTH_FACEBOOK_SCOPE = ['email']
SOCIAL_AUTH_FACEBOOK_PROFILE_EXTRA_PARAMS = {
            'fields': 'id,name,email',
            }
SOCIAL_AUTH_ADMIN_USER_SEARCH_FIELDS = ['username', 'first_name', 'email']

MIDDLEWARE = [
    'debug_toolbar.middleware.DebugToolbarMiddleware', # new
    'django.middleware.security.SecurityMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'social_django.middleware.SocialAuthExceptionMiddleware',  # new
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',

1 个答案:

答案 0 :(得分:1)

您必须将localhost作为ssl服务器运行。

pip install django-sslserver

将应用程序添加到您的INSTALLED_APPS:

INSTALLED_APPS = (...
"sslserver",
...
)

然后运行:

python manage.py runsslserver