Djanogo-用于社交媒体登录的Python Social Auth

时间:2019-08-28 23:44:20

标签: python django python-social-auth

我正在尝试使用python-social-auth让用户使用其Facebook或google帐户登录。用户获得google登录页面并登录其帐户后,我将无法重定向回我的网站。它说

  

无法访问此网站 127.0.0.1需要很长时间才能响应。

我遵循了文档:https://python-social-auth.readthedocs.io/en/latest/configuration/django.html

以下内容位于 settings.py 中:

SOCIAL_AUTH_GOOGLE_OAUTH2_KEY  = "xxxxxxxxxxxxxxxxx"
SOCIAL_AUTH_GOOGLE_OAUTH2_SECRET  = "xxxxxxxxxxxxxxxxx"

INSTALLED_APPS = [
   ...
   ...
   'social_django',
   ...  
]

MIDDLEWARE = [
...
'social_django.middleware.SocialAuthExceptionMiddleware',
]

TEMPLATES = [
{
    ...
        'context_processors': [
            ...
            'social_django.context_processors.backends',  # <--
            'social_django.context_processors.login_redirect', # <--
        ],
    },
 },
]

AUTHENTICATION_BACKENDS = (
'social_core.backends.google.GoogleOAuth2',
'social_core.backends.twitter.TwitterOAuth',
'social_core.backends.facebook.FacebookOAuth2',
'django.contrib.auth.backends.ModelBackend',
) 

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

在google OAuth客户端中,在“授权重定向URI”下,我有:https://127.0.0.1:8000/oauth/complete/google-oauth2/

0 个答案:

没有答案