@@ -462,9 +462,9 @@ async def on_POST(self, request: SynapseRequest) -> Tuple[int, JsonDict]:
462462 # the auth layer will store these in sessions.
463463 desired_username = None
464464 if "username" in body :
465- if not isinstance (body ["username" ], str ) or len (body ["username" ]) > 512 :
466- raise SynapseError (400 , "Invalid username" )
467465 desired_username = body ["username" ]
466+ if not isinstance (desired_username , str ) or len (desired_username ) > 512 :
467+ raise SynapseError (400 , "Invalid username" )
468468
469469 # fork off as soon as possible for ASes which have completely
470470 # different registration flows to normal users
@@ -477,19 +477,15 @@ async def on_POST(self, request: SynapseRequest) -> Tuple[int, JsonDict]:
477477 "Appservice token must be provided when using a type of m.login.application_service" ,
478478 )
479479
480- # Set the desired user according to the AS API (which uses the
481- # 'user' key not 'username'). Since this is a new addition, we'll
482- # fallback to 'username' if they gave one.
483- desired_username = body .get ("user" , desired_username )
484-
485480 # XXX we should check that desired_username is valid. Currently
486481 # we give appservices carte blanche for any insanity in mxids,
487482 # because the IRC bridges rely on being able to register stupid
488483 # IDs.
489484
490485 access_token = self .auth .get_access_token_from_request (request )
491486
492- if not isinstance (desired_username , str ):
487+ # Desired username is either a string or None.
488+ if desired_username is None :
493489 raise SynapseError (400 , "Desired Username is missing or not a string" )
494490
495491 result = await self ._do_appservice_registration (
0 commit comments