簡體   English   中英

如何在Django中的localhost上運行Facebook身份驗證?

[英]How to run Facebook authentication on localhost in Django?

我已經在StackOverFlow上閱讀了有關此問題的所有討論,但它們似乎都已過時。

有誰知道如何通過social-auth-app-django在Django中的localhost上運行facebook身份驗證? 我大概花了一天左右的時間來解決它,但是沒有任何效果。

在此處輸入圖片說明

在此處輸入圖片說明


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',

您必須將localhost作為ssl服務器運行。

pip install django-sslserver

將應用程序添加到您的INSTALLED_APPS:

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

並運行:

python manage.py runsslserver

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM