mirror of
https://github.com/element-hq/synapse.git
synced 2024-11-28 15:08:49 +03:00
Simplify appservice login code (#8847)
we don't need to support legacy login dictionaries here.
This commit is contained in:
parent
9f0f274fe0
commit
59e18a1333
2 changed files with 22 additions and 6 deletions
1
changelog.d/8847.misc
Normal file
1
changelog.d/8847.misc
Normal file
|
@ -0,0 +1 @@
|
||||||
|
Simplify `uk.half-shot.msc2778.login.application_service` login handler.
|
|
@ -154,13 +154,28 @@ class LoginRestServlet(RestServlet):
|
||||||
async def _do_appservice_login(
|
async def _do_appservice_login(
|
||||||
self, login_submission: JsonDict, appservice: ApplicationService
|
self, login_submission: JsonDict, appservice: ApplicationService
|
||||||
):
|
):
|
||||||
logger.info(
|
identifier = login_submission.get("identifier")
|
||||||
"Got appservice login request with identifier: %r",
|
logger.info("Got appservice login request with identifier: %r", identifier)
|
||||||
login_submission.get("identifier"),
|
|
||||||
)
|
|
||||||
|
|
||||||
identifier = convert_client_dict_legacy_fields_to_identifier(login_submission)
|
if not isinstance(identifier, dict):
|
||||||
qualified_user_id = self._get_qualified_user_id(identifier)
|
raise SynapseError(
|
||||||
|
400, "Invalid identifier in login submission", Codes.INVALID_PARAM
|
||||||
|
)
|
||||||
|
|
||||||
|
# this login flow only supports identifiers of type "m.id.user".
|
||||||
|
if identifier.get("type") != "m.id.user":
|
||||||
|
raise SynapseError(
|
||||||
|
400, "Unknown login identifier type", Codes.INVALID_PARAM
|
||||||
|
)
|
||||||
|
|
||||||
|
user = identifier.get("user")
|
||||||
|
if not isinstance(user, str):
|
||||||
|
raise SynapseError(400, "Invalid user in identifier", Codes.INVALID_PARAM)
|
||||||
|
|
||||||
|
if user.startswith("@"):
|
||||||
|
qualified_user_id = user
|
||||||
|
else:
|
||||||
|
qualified_user_id = UserID(user, self.hs.hostname).to_string()
|
||||||
|
|
||||||
if not appservice.is_interested_in_user(qualified_user_id):
|
if not appservice.is_interested_in_user(qualified_user_id):
|
||||||
raise LoginError(403, "Invalid access_token", errcode=Codes.FORBIDDEN)
|
raise LoginError(403, "Invalid access_token", errcode=Codes.FORBIDDEN)
|
||||||
|
|
Loading…
Reference in a new issue