Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Allauth/facebook won't send/accept https

I've created an app and deployed it live on digitalocean and enabled HTTPS with certbot, when I want to login with facebook:

enter image description here

I got this error:

enter image description here

and the redirect URL:

enter image description here is not HTTPS:

My code:

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

)

login btn

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

enter image description here

like image 605
Slim yaw Avatar asked Jan 29 '26 23:01

Slim yaw


1 Answers

Try adding the following to your settings:

ACCOUNT_DEFAULT_HTTP_PROTOCOL = 'https'

(see this issue on the allauth github https://github.com/pennersr/django-allauth/issues/1994)

like image 195
Tom Avatar answered Jan 31 '26 13:01

Tom