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

Use the v2 Identity Service API for lookups (MSC2134 + MSC2140) #5976

Merged
merged 40 commits into from
Sep 11, 2019
Merged
Changes from 3 commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
1954438
Use the v2 lookup API
anoadragon453 Aug 21, 2019
24ee3ae
lint
anoadragon453 Aug 21, 2019
902ef39
add changelog
anoadragon453 Aug 21, 2019
3a114fe
linter fight
anoadragon453 Aug 21, 2019
5426e13
Merge branch 'develop' into anoa/v2_lookup
anoadragon453 Aug 21, 2019
73fb6f3
Continue to support v1 lookup
anoadragon453 Aug 21, 2019
2472e2e
lint
anoadragon453 Aug 21, 2019
7bfccad
Address review comments
anoadragon453 Aug 27, 2019
75ef0f8
lint
anoadragon453 Aug 27, 2019
e68d648
small fixes and remove unnecessary Enum
anoadragon453 Aug 28, 2019
38dac27
Warn user when the id_server they chose does not support any of the h…
anoadragon453 Aug 28, 2019
8f1346d
Apply suggestions from code review
anoadragon453 Aug 28, 2019
4dc0849
lint
anoadragon453 Aug 28, 2019
849d8dc
Merge branch 'anoa/v2_lookup' of github.com:matrix-org/synapse into a…
anoadragon453 Aug 28, 2019
d9d156b
Merge branch 'develop' into anoa/v2_lookup
anoadragon453 Sep 3, 2019
42b11bd
use v2 identity service api endpoints for 3pid invites and lookup
anoadragon453 Sep 3, 2019
83021d9
Merge branch 'develop' of github.com:matrix-org/synapse into anoa/v2_…
anoadragon453 Sep 3, 2019
07154ea
Merge branch 'develop' of github.com:matrix-org/synapse into anoa/v2_…
anoadragon453 Sep 3, 2019
f4b7f7f
id_access_token support
anoadragon453 Sep 3, 2019
29c3489
Apply suggestions from code review
anoadragon453 Sep 4, 2019
ff5f6a0
Address review comments
anoadragon453 Sep 4, 2019
a5153af
Merge branch 'anoa/v2_lookup' of github.com:matrix-org/synapse into a…
anoadragon453 Sep 4, 2019
7f647bc
Revert moving lookup stuff to IdentityHandler
anoadragon453 Sep 4, 2019
f8bb859
Fix issues with moving stuff back to RoomMemberHandler
anoadragon453 Sep 4, 2019
1c59243
Factor our v2 invite things
anoadragon453 Sep 4, 2019
1b20928
lint
anoadragon453 Sep 4, 2019
db1d161
whoops
anoadragon453 Sep 4, 2019
9f92c3e
Change lookup_3pid back to a private method
anoadragon453 Sep 4, 2019
07169b1
Apply suggestions from code review
anoadragon453 Sep 5, 2019
5b852c2
Address review comments
anoadragon453 Sep 5, 2019
0d968c0
liiiiiiiiiiiint
anoadragon453 Sep 5, 2019
f18f3f1
address review comments
anoadragon453 Sep 9, 2019
18671b0
lint
anoadragon453 Sep 9, 2019
649dcbe
id_access_token -> access_token in query params
anoadragon453 Sep 10, 2019
b4520ea
Merge branch 'develop' of github.com:matrix-org/synapse into anoa/v2_…
anoadragon453 Sep 11, 2019
79f5c4f
Address review comments.
anoadragon453 Sep 11, 2019
cf8dbea
Merge branch 'develop' of github.com:matrix-org/synapse into anoa/v2_…
anoadragon453 Sep 11, 2019
7008c79
Send id access_token via Authorization headers, not JSON body
anoadragon453 Sep 11, 2019
ffb284e
Merge branch 'develop' of github.com:matrix-org/synapse into anoa/v2_…
anoadragon453 Sep 11, 2019
317dff6
Update changelog.d/5897.feature
anoadragon453 Sep 11, 2019
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
64 changes: 36 additions & 28 deletions synapse/handlers/room_member.py
Original file line number Diff line number Diff line change
Expand Up @@ -710,28 +710,10 @@ def _lookup_3pid(self, id_server, medium, address, id_access_token=None):
Returns:
str|None: the matrix ID of the 3pid, or None if it is not recognized.
"""
# If an access token is present, add it to the query params of the hash_details request
query_params = {}
if id_access_token is not None:
anoadragon453 marked this conversation as resolved.
Show resolved Hide resolved
query_params["id_access_token"] = id_access_token

# Check what hashing details are supported by this identity server
try:
hash_details = yield self.simple_http_client.get_json(
"%s%s/_matrix/identity/v2/hash_details"
% (id_server_scheme, id_server),
query_params,
)
if not isinstance(hash_details, dict):
logger.warning(
"Got non-dict object when checking hash details of %s: %s",
id_server,
hash_details,
)
return None

results = yield self._lookup_3pid_v2(
id_server, id_access_token, medium, address, hash_details
id_server, id_access_token, medium, address
)
return results

Expand Down Expand Up @@ -782,9 +764,7 @@ def _lookup_3pid_v1(self, id_server, medium, address):
return None

@defer.inlineCallbacks
def _lookup_3pid_v2(
self, id_server, id_access_token, medium, address, hash_details
):
def _lookup_3pid_v2(self, id_server, id_access_token, medium, address):
"""Looks up a 3pid in the passed identity server using v2 lookup.

Args:
Expand All @@ -793,12 +773,38 @@ def _lookup_3pid_v2(
id_access_token (str): The access token to authenticate to the identity server with
richvdh marked this conversation as resolved.
Show resolved Hide resolved
medium (str): The type of the third party identifier (e.g. "email").
address (str): The third party identifier (e.g. "[email protected]").
hash_details (dict[str, str|list]): A dictionary containing hashing information
provided by an identity server.

Returns:
Deferred[str|None]: the matrix ID of the 3pid, or None if it is not recognised.
"""
try:
# Check what hashing details are supported by this identity server
hash_details = yield self.simple_http_client.get_json(
"%s%s/_matrix/identity/v2/hash_details" % (id_server_scheme, id_server),
{"access_token": id_access_token},
)
except HttpResponseException as e:
if e.code == 404:
raise

logger.warning("Error when performing a v2 hash_details request: %s", e)
raise SynapseError(
anoadragon453 marked this conversation as resolved.
Show resolved Hide resolved
500, "Unknown error occurred during identity server lookup"
)

if not isinstance(hash_details, dict):
logger.warning(
"Got non-dict object when checking hash details of %s%s: %s",
id_server_scheme,
id_server,
hash_details,
)
raise SynapseError(
400,
"Non-dict object from %s%s during v2 hash_details request: %s"
% (id_server_scheme, id_server, hash_details),
)

# Extract information from hash_details
supported_lookup_algorithms = hash_details.get("algorithms")
lookup_pepper = hash_details.get("lookup_pepper")
Expand All @@ -809,7 +815,9 @@ def _lookup_3pid_v2(
or not isinstance(lookup_pepper, str)
):
raise SynapseError(
richvdh marked this conversation as resolved.
Show resolved Hide resolved
500, "Invalid hash details received from identity server: %s, %s"
400,
"Invalid hash details received from identity server: %s%s, %s"
anoadragon453 marked this conversation as resolved.
Show resolved Hide resolved
% (id_server_scheme, id_server, hash_details),
)

# Check if any of the supported lookup algorithms are present
Expand All @@ -835,7 +843,7 @@ def _lookup_3pid_v2(
supported_lookup_algorithms,
)
raise SynapseError(
400,
500,
anoadragon453 marked this conversation as resolved.
Show resolved Hide resolved
"Provided identity server does not support any v2 lookup "
"algorithms that this homeserver supports.",
)
Expand All @@ -844,7 +852,7 @@ def _lookup_3pid_v2(
lookup_results = yield self.simple_http_client.post_json_get_json(
"%s%s/_matrix/identity/v2/lookup" % (id_server_scheme, id_server),
{
"id_access_token": id_access_token,
"access_token": id_access_token,
"addresses": [lookup_value],
"algorithm": lookup_algorithm,
"pepper": lookup_pepper,
Expand All @@ -860,7 +868,7 @@ def _lookup_3pid_v2(
if "mappings" not in lookup_results or not isinstance(
lookup_results["mappings"], dict
):
logger.debug("No results from 3pid lookup")
logger.warning("No results from 3pid lookup")
return None

# Return the MXID if it's available, or None otherwise
Expand Down