diff --git a/changelog.d/66.bugfix b/changelog.d/66.bugfix new file mode 100644 index 000000000000..9547cfeddd63 --- /dev/null +++ b/changelog.d/66.bugfix @@ -0,0 +1 @@ +Create a mapping between user ID and threepid when binding via the internal Sydent bind API. \ No newline at end of file diff --git a/synapse/handlers/identity.py b/synapse/handlers/identity.py index 558ab24a8f3c..3cf76e954ec8 100644 --- a/synapse/handlers/identity.py +++ b/synapse/handlers/identity.py @@ -1066,6 +1066,9 @@ async def bind_email_using_internal_sydent_api( Raises: HTTPResponseException: On a non-2xx HTTP response. """ + # Extract the domain name from the IS URL as we store IS domains instead of URLs + id_server = urllib.parse.urlparse(id_server_url).hostname + # id_server_url is assumed to have no trailing slashes url = id_server_url + "/_matrix/identity/internal/bind" body = { @@ -1074,8 +1077,14 @@ async def bind_email_using_internal_sydent_api( "mxid": user_id, } + # Bind the threepid await self.http_client.post_json_get_json(url, body) + # Remember where we bound the threepid + await self.store.add_user_bound_threepid( + user_id=user_id, medium="email", address=email, id_server=id_server, + ) + def create_id_access_token_header(id_access_token: str) -> List[str]: """Create an Authorization header for passing to SimpleHttpClient as the header value diff --git a/tests/handlers/test_register.py b/tests/handlers/test_register.py index f5033c94fec5..e951a62a6dc0 100644 --- a/tests/handlers/test_register.py +++ b/tests/handlers/test_register.py @@ -566,6 +566,12 @@ def test_user_email_bound_via_sydent_internal_api(self): {"address": "alice@example.com", "medium": "email", "mxid": "@alice:test"}, ) + # Check that we stored a mapping of this bind + bound_threepids = self.get_success( + self.store.user_get_bound_threepids("@alice:test") + ) + self.assertListEqual(bound_threepids, [{"medium": "email", "address": email}]) + def uia_register(self, expected_response: int, body: dict) -> FakeChannel: """Make a register request.""" request, channel = self.make_request(