django22: Add 'request' as first argument to 'authenticate'

As noted in the Django 2.1 release notes [1]:

  The authenticate() method of authentication backends requires request
  as the first positional argument.

This can be seen here [2]. Simple enough, though it took me ages to
figure this out because Django gave me *zero* warning that a backend
because of this change. Heck, raising the TypeError would have helped :(

[1] https://docs.djangoproject.com/en/2.2/releases/2.1/#features-removed-in-2-1
[2] https://github.com/django/django/commit/5e31be1b96f

Change-Id: I0dd37d33c8e42a70c00a9f1460c1cec86c5b6006
Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
This commit is contained in:
Stephen Finucane 2019-08-26 16:41:33 +01:00
parent 7938f36016
commit fff89e69df
2 changed files with 5 additions and 4 deletions

View File

@ -33,6 +33,8 @@ LOG = logging.getLogger(__name__)
KEYSTONE_CLIENT_ATTR = "_keystoneclient"
# TODO(stephenfin): Subclass 'django.contrib.auth.backends.BaseBackend' once we
# (only) support Django 3.0
class KeystoneBackend(object):
"""Django authentication backend for use with ``django.contrib.auth``."""
@ -99,7 +101,7 @@ class KeystoneBackend(object):
'configuration error that should be addressed.')
raise exceptions.KeystoneAuthException(msg)
def authenticate(self, auth_url=None, **kwargs):
def authenticate(self, request, auth_url=None, **kwargs):
"""Authenticates a user via the Keystone Identity API."""
LOG.debug('Beginning user authentication')
@ -117,7 +119,6 @@ class KeystoneBackend(object):
# the recent project id a user might have set in a cookie
recent_project = None
request = kwargs.get('request')
if request:
# Grab recent_project found in the cookie, try to scope
# to the last project used.

View File

@ -161,7 +161,7 @@ def websso(request):
auth_url = utils.clean_up_auth_url(referer)
token = request.POST.get('token')
try:
request.user = auth.authenticate(request=request, auth_url=auth_url,
request.user = auth.authenticate(request, auth_url=auth_url,
token=token)
except exceptions.KeystoneAuthException as exc:
if utils.is_websso_default_redirect():
@ -330,7 +330,7 @@ def switch_keystone_provider(request, keystone_provider=None,
if unscoped_auth_ref:
try:
request.user = auth.authenticate(
request=request, auth_url=unscoped_auth.auth_url,
request, auth_url=unscoped_auth.auth_url,
token=unscoped_auth_ref.auth_token)
except exceptions.KeystoneAuthException as exc:
msg = 'Keystone provider switch failed: %s' % six.text_type(exc)