diff --git a/authentik/core/middleware.py b/authentik/core/middleware.py index 64400b64b..58a821197 100644 --- a/authentik/core/middleware.py +++ b/authentik/core/middleware.py @@ -26,6 +26,8 @@ class ImpersonateMiddleware: if SESSION_IMPERSONATE_USER in request.session: request.user = request.session[SESSION_IMPERSONATE_USER] + # Ensure that the user is active, otherwise nothing will work + request.user.is_active = True return self.get_response(request) diff --git a/authentik/core/tests/test_impersonation.py b/authentik/core/tests/test_impersonation.py index 9a30ba16c..36bf5ee71 100644 --- a/authentik/core/tests/test_impersonation.py +++ b/authentik/core/tests/test_impersonation.py @@ -17,6 +17,9 @@ class TestImpersonation(TestCase): def test_impersonate_simple(self): """test simple impersonation and un-impersonation""" + # test with an inactive user to ensure that still works + self.other_user.is_active = False + self.other_user.save() self.client.force_login(self.akadmin) self.client.get(