allauth / facebook赢了发送/接受https

时间:2018-03-31 11:17:49

标签: facebook django-allauth

我想创建一个应用程序并在digitalocean上实时部署它并使用certbot启用HTTPS,当我想用​​facebook登录时 enter image description here

我收到了这个错误 enter image description here

且重定向网址enter image description here不是HTTPS:

我的代码:

INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.sites',
'social_django',
'allauth',
'allauth.account',
'allauth.socialaccount',
'allauth.socialaccount.providers.facebook',

SOCIALACCOUNT_PROVIDERS = {
'facebook': {
    'METHOD': 'oauth2',
    'SCOPE': ['email', 'public_profile'],
    'AUTH_PARAMS': {'auth_type': 'reauthenticate'},
    'INIT_PARAMS': {'cookie': True},
    '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.12',
}

}

SOCIAL_AUTH_REDIRECT_IS_HTTPS = True

AUTHENTICATION_BACKENDS = (
'django.contrib.auth.backends.ModelBackend',
# 'social_core.backends.facebook.FacebookOAuth2',
'allauth.account.auth_backends.AuthenticationBackend',

登录btn

{% load socialaccount %}
<a href="{% provider_login_url "facebook" method="oauth2" %}">Facebook OAuth2</a>

enter image description here

1 个答案:

答案 0 :(得分:2)

尝试在您的设置中添加以下内容:

ACCOUNT_DEFAULT_HTTP_PROTOCOL = 'https'

(请参阅allauth github https://github.com/pennersr/django-allauth/issues/1994上的此问题)