diff --git a/changelog.d/66.bugfix b/changelog.d/66.bugfix
new file mode 100644
index 0000000000..9547cfeddd
--- /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 558ab24a8f..3cf76e954e 100644
--- a/synapse/handlers/identity.py
+++ b/synapse/handlers/identity.py
@@ -1066,6 +1066,9 @@ class IdentityHandler(BaseHandler):
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 @@ class IdentityHandler(BaseHandler):
"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 f5033c94fe..e951a62a6d 100644
--- a/tests/handlers/test_register.py
+++ b/tests/handlers/test_register.py
@@ -566,6 +566,12 @@ class RegistrationTestCase(unittest.HomeserverTestCase):
{"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(
|