From fff89e69dfa941b389b82fd8cc9118818eaaf740 Mon Sep 17 00:00:00 2001 From: Stephen Finucane Date: Mon, 26 Aug 2019 16:41:33 +0100 Subject: [PATCH] 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 --- openstack_auth/backend.py | 5 +++-- openstack_auth/views.py | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/openstack_auth/backend.py b/openstack_auth/backend.py index 8116cabcec..2a46584a26 100644 --- a/openstack_auth/backend.py +++ b/openstack_auth/backend.py @@ -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. diff --git a/openstack_auth/views.py b/openstack_auth/views.py index 1fbf556440..7dcfc5eee2 100644 --- a/openstack_auth/views.py +++ b/openstack_auth/views.py @@ -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)