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

Commit a2b8233

Browse files
Remember mappings when we bind a 3pid using the internal sydent bind API (#66)
#51 added an option that would automatically bind a user's threepid to a configured identity server after they had registered. Unfortunately, when you bind threepids, ideally you would store that mapping in the database so that later on you can remove those mappings when you deactivate an account. We found that due the fact that we did not store these mappings, threepids were not unbound upon user account deactivation. This PR fixes the issue by creating the mappings again, meaning they will again be removed upon account deactivation.
1 parent 722e1c0 commit a2b8233

File tree

3 files changed

+16
-0
lines changed

3 files changed

+16
-0
lines changed

changelog.d/66.bugfix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Create a mapping between user ID and threepid when binding via the internal Sydent bind API.

synapse/handlers/identity.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1066,6 +1066,9 @@ async def bind_email_using_internal_sydent_api(
10661066
Raises:
10671067
HTTPResponseException: On a non-2xx HTTP response.
10681068
"""
1069+
# Extract the domain name from the IS URL as we store IS domains instead of URLs
1070+
id_server = urllib.parse.urlparse(id_server_url).hostname
1071+
10691072
# id_server_url is assumed to have no trailing slashes
10701073
url = id_server_url + "/_matrix/identity/internal/bind"
10711074
body = {
@@ -1074,8 +1077,14 @@ async def bind_email_using_internal_sydent_api(
10741077
"mxid": user_id,
10751078
}
10761079

1080+
# Bind the threepid
10771081
await self.http_client.post_json_get_json(url, body)
10781082

1083+
# Remember where we bound the threepid
1084+
await self.store.add_user_bound_threepid(
1085+
user_id=user_id, medium="email", address=email, id_server=id_server,
1086+
)
1087+
10791088

10801089
def create_id_access_token_header(id_access_token: str) -> List[str]:
10811090
"""Create an Authorization header for passing to SimpleHttpClient as the header value

tests/handlers/test_register.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -566,6 +566,12 @@ def test_user_email_bound_via_sydent_internal_api(self):
566566
{"address": "[email protected]", "medium": "email", "mxid": "@alice:test"},
567567
)
568568

569+
# Check that we stored a mapping of this bind
570+
bound_threepids = self.get_success(
571+
self.store.user_get_bound_threepids("@alice:test")
572+
)
573+
self.assertListEqual(bound_threepids, [{"medium": "email", "address": email}])
574+
569575
def uia_register(self, expected_response: int, body: dict) -> FakeChannel:
570576
"""Make a register request."""
571577
request, channel = self.make_request(

0 commit comments

Comments
 (0)