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

Remember mappings when we bind a 3pid using the internal sydent bind API #66

Merged
merged 3 commits into from
Oct 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/66.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Create a mapping between user ID and threepid when binding via the internal Sydent bind API.
9 changes: 9 additions & 0 deletions synapse/handlers/identity.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -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
Expand Down
6 changes: 6 additions & 0 deletions tests/handlers/test_register.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down