'can't login with facebook using allauth library using Django because of CSRF token and gave me CSRF verification failed. Request aborted
i have a server deployed in AWS using Django and every thing working fine until i tap on login with facebook Button it shows the normal facebook login popup and after typing my email and password instead of going to the next page it gave me CSRF verification failed. Request aborted.
as you can see i've {% csrf_token %} in the code for showing login with facebook button using js_sdk:
{% extends 'restaurant/base_auth.html' %}
{% load bootstrap4 %}
{% block title %}Akalat-Shop{% endblock %}
{% block heading %}Akalat-Shop - Sign In{% endblock %}
{% block content %}
{% load socialaccount %}
{% providers_media_js %}
<a href="{% provider_login_url "facebook" method="js_sdk" %}">Login with Facebook</a>
<form action="" method="post">
{% csrf_token %}
{% bootstrap_form form %}
<button type="submit" class="btn btn-primary btn-block">Sign In</button>
</form>
<div class="text-center mt-3">
<a href="{% url 'restaurant_sign_up' %}">Become a Restaurant</a>
</div>
{% endblock %}
also i tried those in settings.py :
LOGIN_REDIRECT_URL = '/'
ACCOUNT_DEFAULT_HTTP_PROTOCOL = 'https'
SOCIAL_AUTH_REDIRECT_IS_HTTPS = True
//all configurations of facebook login
my views.py i've checked also for using @csrf_exempt:
from django.views.decorators.csrf import csrf_exempt
@csrf_exempt
@login_required(login_url="/restaurant/sign_in/")
def restaurant_home(request):
return redirect(restaurant_order)
from django.views.decorators.csrf import csrf_exempt
@csrf_exempt
@login_required(login_url="/restaurant/sign_in/")
def restaurant_order(request):
if request.method == "POST":
order = Order.objects.get(id=request.POST["id"])
if order.status == Order.COOKING:
order.status = Order.READY
order.save()
orders = Order.objects.filter(restaurant = request.user.restaurant).order_by("-id")
return render(request, 'restaurant/order.html', {"orders": orders})
my configurations in facebook dashboard for callback url in the screenshot below:
i don't know where is the problem but may be from using js_sdk in facebook login caused this block and thanks in advance for helping ✨🤝
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|


