prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  Session duration not working correctly
  **Describe the bug**
  I changed the session duration of the default-authentication-login to 18 hours. Still, after a login the session is valid for 14 days.
  For me, it looks like the session duration value is ignored.
  
  **To Reproduce**
  Steps to reproduce the behavior:
  1. Go to 'Admin interface'
  2. Click on 'Flows & Stages'
  3. Edit 'default-authentication-login'
  4. Change 'Session duration' to 'hours=18;minutes=0;seconds=0'
  5. Logout & Login
  6. Click on the settings-icon (“wheel”)
  7. Check the session duration.
  
  **Expected behavior**
  I want to achieve, that every user has to authenticate once a day. Therefore, the session duration of 18 hours. 
  
  **Screenshots**
  ![image](https://user-images.githubusercontent.com/7803347/224706556-5ec007cf-9b0c-4aeb-9160-d6d779bfcc7b.png)
  ![image](https://user-images.githubusercontent.com/7803347/224707352-97c11b3c-672b-4355-bbb9-e603522217cb.png)
  
  
  **Logs**
  There are no logs.
  
  **Version and Deployment (please complete the following information):**
   - authentik 2023.1.2
   - Deployment: docker-compose
  
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `authentik/stages/user_login/stage.py`
  Content:
  ```
  1 """Login stage logic"""
  2 from django.contrib import messages
  3 from django.contrib.auth import login
  4 from django.http import HttpRequest, HttpResponse
  5 from django.utils.translation import gettext as _
  6 
  7 from authentik.core.models import AuthenticatedSession, User
  8 from authentik.flows.planner import PLAN_CONTEXT_PENDING_USER, PLAN_CONTEXT_SOURCE
  9 from authentik.flows.stage import StageView
  10 from authentik.lib.utils.time import timedelta_from_string
  11 from authentik.stages.password import BACKEND_INBUILT
  12 from authentik.stages.password.stage import PLAN_CONTEXT_AUTHENTICATION_BACKEND
  13 
  14 
  15 class UserLoginStageView(StageView):
  16     """Finalise Authentication flow by logging the user in"""
  17 
  18     def post(self, request: HttpRequest) -> HttpResponse:
  19         """Wrapper for post requests"""
  20         return self.get(request)
  21 
  22     def get(self, request: HttpRequest) -> HttpResponse:
  23         """Attach the currently pending user to the current session"""
  24         if PLAN_CONTEXT_PENDING_USER not in self.executor.plan.context:
  25             message = _("No Pending user to login.")
  26             messages.error(request, message)
  27             self.logger.debug(message)
  28             return self.executor.stage_invalid()
  29         backend = self.executor.plan.context.get(
  30             PLAN_CONTEXT_AUTHENTICATION_BACKEND, BACKEND_INBUILT
  31         )
  32         user: User = self.executor.plan.context[PLAN_CONTEXT_PENDING_USER]
  33         if not user.is_active:
  34             self.logger.warning("User is not active, login will not work.")
  35         login(
  36             self.request,
  37             user,
  38             backend=backend,
  39         )
  40         delta = timedelta_from_string(self.executor.current_stage.session_duration)
  41         if delta.total_seconds() == 0:
  42             self.request.session.set_expiry(0)
  43         else:
  44             self.request.session.set_expiry(delta)
  45         self.logger.debug(
  46             "Logged in",
  47             backend=backend,
  48             user=user.username,
  49             flow_slug=self.executor.flow.slug,
  50             session_duration=self.executor.current_stage.session_duration,
  51         )
  52         # Only show success message if we don't have a source in the flow
  53         # as sources show their own success messages
  54         if not self.executor.plan.context.get(PLAN_CONTEXT_SOURCE, None):
  55             messages.success(self.request, _("Successfully logged in!"))
  56         if self.executor.current_stage.terminate_other_sessions:
  57             AuthenticatedSession.objects.filter(
  58                 user=user,
  59             ).exclude(session_key=self.request.session.session_key).delete()
  60         return self.executor.stage_ok()
  61
  ```
  --- END FILES ---
  
  Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.
  
  Here is an example:
  
  ```diff
  diff --git a/examples/server_async.py b/examples/server_async.py
  --- a/examples/server_async.py
  +++ b/examples/server_async.py
  @@ -313,4 +313,4 @@
   
   
   if __name__ == "__main__":
  -    asyncio.run(run_async_server("."), debug=True)
  +    asyncio.run(run_async_server(), debug=True)
  diff --git a/examples/server_sync.py b/examples/server_sync.py
  --- a/examples/server_sync.py
  +++ b/examples/server_sync.py
  @@ -313,5 +313,5 @@
   
   
   if __name__ == "__main__":
  -    server = run_sync_server(".")
  +    server = run_sync_server()
       server.shutdown()
  
  ```
  
golden_diff: diff --git a/authentik/stages/user_login/stage.py b/authentik/stages/user_login/stage.py
  --- a/authentik/stages/user_login/stage.py
  +++ b/authentik/stages/user_login/stage.py
  @@ -32,16 +32,16 @@
           user: User = self.executor.plan.context[PLAN_CONTEXT_PENDING_USER]
           if not user.is_active:
               self.logger.warning("User is not active, login will not work.")
  -        login(
  -            self.request,
  -            user,
  -            backend=backend,
  -        )
           delta = timedelta_from_string(self.executor.current_stage.session_duration)
           if delta.total_seconds() == 0:
               self.request.session.set_expiry(0)
           else:
               self.request.session.set_expiry(delta)
  +        login(
  +            self.request,
  +            user,
  +            backend=backend,
  +        )
           self.logger.debug(
               "Logged in",
               backend=backend,
  
verification_info: {"golden_diff": "diff --git a/authentik/stages/user_login/stage.py b/authentik/stages/user_login/stage.py\n--- a/authentik/stages/user_login/stage.py\n+++ b/authentik/stages/user_login/stage.py\n@@ -32,16 +32,16 @@\n         user: User = self.executor.plan.context[PLAN_CONTEXT_PENDING_USER]\n         if not user.is_active:\n             self.logger.warning(\"User is not active, login will not work.\")\n-        login(\n-            self.request,\n-            user,\n-            backend=backend,\n-        )\n         delta = timedelta_from_string(self.executor.current_stage.session_duration)\n         if delta.total_seconds() == 0:\n             self.request.session.set_expiry(0)\n         else:\n             self.request.session.set_expiry(delta)\n+        login(\n+            self.request,\n+            user,\n+            backend=backend,\n+        )\n         self.logger.debug(\n             \"Logged in\",\n             backend=backend,\n", "issue": "Session duration not working correctly\n**Describe the bug**\r\nI changed the session duration of the default-authentication-login to 18 hours. Still, after a login the session is valid for 14 days.\r\nFor me, it looks like the session duration value is ignored.\r\n\r\n**To Reproduce**\r\nSteps to reproduce the behavior:\r\n1. Go to 'Admin interface'\r\n2. Click on 'Flows & Stages'\r\n3. Edit 'default-authentication-login'\r\n4. Change 'Session duration' to 'hours=18;minutes=0;seconds=0'\r\n5. Logout & Login\r\n6. Click on the settings-icon (\u201cwheel\u201d)\r\n7. Check the session duration.\r\n\r\n**Expected behavior**\r\nI want to achieve, that every user has to authenticate once a day. Therefore, the session duration of 18 hours. \r\n\r\n**Screenshots**\r\n![image](https://user-images.githubusercontent.com/7803347/224706556-5ec007cf-9b0c-4aeb-9160-d6d779bfcc7b.png)\r\n![image](https://user-images.githubusercontent.com/7803347/224707352-97c11b3c-672b-4355-bbb9-e603522217cb.png)\r\n\r\n\r\n**Logs**\r\nThere are no logs.\r\n\r\n**Version and Deployment (please complete the following information):**\r\n - authentik 2023.1.2\r\n - Deployment: docker-compose\r\n\n", "before_files": [{"content": "\"\"\"Login stage logic\"\"\"\nfrom django.contrib import messages\nfrom django.contrib.auth import login\nfrom django.http import HttpRequest, HttpResponse\nfrom django.utils.translation import gettext as _\n\nfrom authentik.core.models import AuthenticatedSession, User\nfrom authentik.flows.planner import PLAN_CONTEXT_PENDING_USER, PLAN_CONTEXT_SOURCE\nfrom authentik.flows.stage import StageView\nfrom authentik.lib.utils.time import timedelta_from_string\nfrom authentik.stages.password import BACKEND_INBUILT\nfrom authentik.stages.password.stage import PLAN_CONTEXT_AUTHENTICATION_BACKEND\n\n\nclass UserLoginStageView(StageView):\n    \"\"\"Finalise Authentication flow by logging the user in\"\"\"\n\n    def post(self, request: HttpRequest) -> HttpResponse:\n        \"\"\"Wrapper for post requests\"\"\"\n        return self.get(request)\n\n    def get(self, request: HttpRequest) -> HttpResponse:\n        \"\"\"Attach the currently pending user to the current session\"\"\"\n        if PLAN_CONTEXT_PENDING_USER not in self.executor.plan.context:\n            message = _(\"No Pending user to login.\")\n            messages.error(request, message)\n            self.logger.debug(message)\n            return self.executor.stage_invalid()\n        backend = self.executor.plan.context.get(\n            PLAN_CONTEXT_AUTHENTICATION_BACKEND, BACKEND_INBUILT\n        )\n        user: User = self.executor.plan.context[PLAN_CONTEXT_PENDING_USER]\n        if not user.is_active:\n            self.logger.warning(\"User is not active, login will not work.\")\n        login(\n            self.request,\n            user,\n            backend=backend,\n        )\n        delta = timedelta_from_string(self.executor.current_stage.session_duration)\n        if delta.total_seconds() == 0:\n            self.request.session.set_expiry(0)\n        else:\n            self.request.session.set_expiry(delta)\n        self.logger.debug(\n            \"Logged in\",\n            backend=backend,\n            user=user.username,\n            flow_slug=self.executor.flow.slug,\n            session_duration=self.executor.current_stage.session_duration,\n        )\n        # Only show success message if we don't have a source in the flow\n        # as sources show their own success messages\n        if not self.executor.plan.context.get(PLAN_CONTEXT_SOURCE, None):\n            messages.success(self.request, _(\"Successfully logged in!\"))\n        if self.executor.current_stage.terminate_other_sessions:\n            AuthenticatedSession.objects.filter(\n                user=user,\n            ).exclude(session_key=self.request.session.session_key).delete()\n        return self.executor.stage_ok()\n", "path": "authentik/stages/user_login/stage.py"}], "after_files": [{"content": "\"\"\"Login stage logic\"\"\"\nfrom django.contrib import messages\nfrom django.contrib.auth import login\nfrom django.http import HttpRequest, HttpResponse\nfrom django.utils.translation import gettext as _\n\nfrom authentik.core.models import AuthenticatedSession, User\nfrom authentik.flows.planner import PLAN_CONTEXT_PENDING_USER, PLAN_CONTEXT_SOURCE\nfrom authentik.flows.stage import StageView\nfrom authentik.lib.utils.time import timedelta_from_string\nfrom authentik.stages.password import BACKEND_INBUILT\nfrom authentik.stages.password.stage import PLAN_CONTEXT_AUTHENTICATION_BACKEND\n\n\nclass UserLoginStageView(StageView):\n    \"\"\"Finalise Authentication flow by logging the user in\"\"\"\n\n    def post(self, request: HttpRequest) -> HttpResponse:\n        \"\"\"Wrapper for post requests\"\"\"\n        return self.get(request)\n\n    def get(self, request: HttpRequest) -> HttpResponse:\n        \"\"\"Attach the currently pending user to the current session\"\"\"\n        if PLAN_CONTEXT_PENDING_USER not in self.executor.plan.context:\n            message = _(\"No Pending user to login.\")\n            messages.error(request, message)\n            self.logger.debug(message)\n            return self.executor.stage_invalid()\n        backend = self.executor.plan.context.get(\n            PLAN_CONTEXT_AUTHENTICATION_BACKEND, BACKEND_INBUILT\n        )\n        user: User = self.executor.plan.context[PLAN_CONTEXT_PENDING_USER]\n        if not user.is_active:\n            self.logger.warning(\"User is not active, login will not work.\")\n        delta = timedelta_from_string(self.executor.current_stage.session_duration)\n        if delta.total_seconds() == 0:\n            self.request.session.set_expiry(0)\n        else:\n            self.request.session.set_expiry(delta)\n        login(\n            self.request,\n            user,\n            backend=backend,\n        )\n        self.logger.debug(\n            \"Logged in\",\n            backend=backend,\n            user=user.username,\n            flow_slug=self.executor.flow.slug,\n            session_duration=self.executor.current_stage.session_duration,\n        )\n        # Only show success message if we don't have a source in the flow\n        # as sources show their own success messages\n        if not self.executor.plan.context.get(PLAN_CONTEXT_SOURCE, None):\n            messages.success(self.request, _(\"Successfully logged in!\"))\n        if self.executor.current_stage.terminate_other_sessions:\n            AuthenticatedSession.objects.filter(\n                user=user,\n            ).exclude(session_key=self.request.session.session_key).delete()\n        return self.executor.stage_ok()\n", "path": "authentik/stages/user_login/stage.py"}]}