Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Commit

Permalink
handle multiple matches
Browse files Browse the repository at this point in the history
  • Loading branch information
OmmyZhang committed Sep 21, 2020
1 parent 4b04c57 commit 2606ed8
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions synapse/handlers/oidc_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -908,12 +908,21 @@ async def _map_userinfo_to_user(
localpart = map_username_to_mxid_localpart(attributes["localpart"])

user_id = UserID(localpart, self._hostname)
matches = await self._datastore.get_users_by_id_case_insensitive(
users = await self._datastore.get_users_by_id_case_insensitive(
user_id.to_string()
)
if matches:
if users:
if self._allow_existing_users:
registered_user_id = next(iter(matches))
if len(users) == 1:
registered_user_id = next(iter(users))
elif user_id in users:
registered_user_id = user_id
else:
raise MappingException(
"Attempted to login as '{}' but it matches more than one user inexactly: {}".format(
user_id.to_string(), list(users.keys())
)
)
else:
# This mxid is taken
raise MappingException(
Expand Down

0 comments on commit 2606ed8

Please sign in to comment.