@@ -302,12 +302,9 @@ async def get_appservice_user(
302302 (the user_id URI parameter allows an application service to masquerade
303303 any applicable user in its namespace)
304304 - what device the application service should be treated as controlling
305- (the device_id[^1] URI parameter allows an application service to masquerade
305+ (the device_id URI parameter allows an application service to masquerade
306306 as any device that exists for the relevant user)
307307
308- [^1] Unstable and provided by MSC3202.
309- Must use `org.matrix.msc3202.device_id` in place of `device_id` for now.
310-
311308 Returns:
312309 the application service `Requester` of that request
313310
@@ -319,7 +316,8 @@ async def get_appservice_user(
319316 - The returned device ID, if present, has been checked to be a valid device ID
320317 for the returned user ID.
321318 """
322- DEVICE_ID_ARG_NAME = b"org.matrix.msc3202.device_id"
319+ # TODO: We can drop unstable support after 2026-01-01 (couple months after stable support)
320+ UNSTABLE_DEVICE_ID_ARG_NAME = b"org.matrix.msc3202.device_id"
323321
324322 app_service = self .store .get_app_service_by_token (access_token )
325323 if app_service is None :
@@ -341,13 +339,11 @@ async def get_appservice_user(
341339 else :
342340 effective_user_id = app_service .sender
343341
344- effective_device_id : Optional [str ] = None
345-
346- if (
347- self .hs .config .experimental .msc3202_device_masquerading_enabled
348- and DEVICE_ID_ARG_NAME in request .args
349- ):
350- effective_device_id = request .args [DEVICE_ID_ARG_NAME ][0 ].decode ("utf8" )
342+ effective_device_id_args = request .args .get (
343+ b"device_id" , request .args .get (UNSTABLE_DEVICE_ID_ARG_NAME )
344+ )
345+ if effective_device_id_args :
346+ effective_device_id = effective_device_id_args [0 ].decode ("utf8" )
351347 # We only just set this so it can't be None!
352348 assert effective_device_id is not None
353349 device_opt = await self .store .get_device (
@@ -359,6 +355,8 @@ async def get_appservice_user(
359355 f"Application service trying to use a device that doesn't exist ('{ effective_device_id } ' for { effective_user_id } )" ,
360356 Codes .UNKNOWN_DEVICE ,
361357 )
358+ else :
359+ effective_device_id = None
362360
363361 return create_requester (
364362 effective_user_id , app_service = app_service , device_id = effective_device_id
0 commit comments