@@ -226,6 +226,9 @@ def __init__(self, hs: "HomeServer"):
226
226
burst_count = self .hs .config .rc_login_failed_attempts .burst_count ,
227
227
)
228
228
229
+ # The number of seconds to keep a UI auth session active.
230
+ self ._ui_auth_session_timeout = hs .config .ui_auth_session_timeout
231
+
229
232
# Ratelimitier for failed /login attempts
230
233
self ._failed_login_attempts_ratelimiter = Ratelimiter (
231
234
clock = hs .get_clock (),
@@ -283,7 +286,7 @@ async def validate_user_via_ui_auth(
283
286
request_body : Dict [str , Any ],
284
287
clientip : str ,
285
288
description : str ,
286
- ) -> Tuple [dict , str ]:
289
+ ) -> Tuple [dict , Optional [ str ] ]:
287
290
"""
288
291
Checks that the user is who they claim to be, via a UI auth.
289
292
@@ -310,7 +313,8 @@ async def validate_user_via_ui_auth(
310
313
have been given only in a previous call).
311
314
312
315
'session_id' is the ID of this session, either passed in by the
313
- client or assigned by this call
316
+ client or assigned by this call. This is None if UI auth was
317
+ skipped (by re-using a previous validation).
314
318
315
319
Raises:
316
320
InteractiveAuthIncompleteError if the client has not yet completed
@@ -324,6 +328,19 @@ async def validate_user_via_ui_auth(
324
328
325
329
"""
326
330
331
+ if self ._ui_auth_session_timeout :
332
+ last_validated = await self .store .get_access_token_last_validated (
333
+ requester .access_token_id
334
+ )
335
+ if (
336
+ self .clock .time_msec () - last_validated
337
+ < self ._ui_auth_session_timeout
338
+ ):
339
+ # Return the input parameters, minus the auth key, which matches
340
+ # the logic in check_ui_auth.
341
+ request_body .pop ("auth" , None )
342
+ return request_body , None
343
+
327
344
user_id = requester .user .to_string ()
328
345
329
346
# Check if we should be ratelimited due to too many previous failed attempts
@@ -455,13 +472,10 @@ async def check_ui_auth(
455
472
all the stages in any of the permitted flows.
456
473
"""
457
474
458
- authdict = None
459
475
sid = None # type: Optional[str]
460
- if clientdict and "auth" in clientdict :
461
- authdict = clientdict ["auth" ]
462
- del clientdict ["auth" ]
463
- if "session" in authdict :
464
- sid = authdict ["session" ]
476
+ authdict = clientdict .pop ("auth" , {})
477
+ if "session" in authdict :
478
+ sid = authdict ["session" ]
465
479
466
480
# Convert the URI and method to strings.
467
481
uri = request .uri .decode ("utf-8" )
0 commit comments