Fixes #6305 : add compatibility to legacy Django 1.11 version

This commit is contained in:
Antonin 2018-11-05 09:52:18 +01:00
parent fae7e91728
commit f6277d877c

View File

@ -6,6 +6,7 @@ from __future__ import unicode_literals
import base64
import binascii
from django import VERSION as django_version
from django.contrib.auth import authenticate, get_user_model
from django.middleware.csrf import CsrfViewMiddleware
from django.utils.six import text_type
@ -137,7 +138,13 @@ class SessionAuthentication(BaseAuthentication):
"""
check = CSRFCheck()
# populates request.META['CSRF_COOKIE'], which is used in process_view()
check.process_request(request)
if tuple(django_version[:3]) < (1, 11, 6):
csrf_token = check._get_token(request)
if csrf_token is not None:
request.META['CSRF_COOKIE'] = csrf_token
else:
check.process_request(request)
reason = check.process_view(request, None, (), {})
if reason:
# CSRF failed, bail with explicit error message