21
21
import urllib .parse
22
22
from typing import Awaitable , Callable , Dict , List , Optional , Tuple
23
23
24
- from canonicaljson import json
25
-
26
- from twisted .internet import defer
27
24
from twisted .internet .error import TimeoutError
28
25
29
26
from synapse .api .errors import (
37
34
from synapse .config .emailconfig import ThreepidBehaviour
38
35
from synapse .http .client import SimpleHttpClient
39
36
from synapse .types import JsonDict , Requester
37
+ from synapse .util import json_decoder
40
38
from synapse .util .hash import sha256_and_url_safe_base64
41
39
from synapse .util .stringutils import assert_valid_client_secret , random_string
42
40
@@ -197,7 +195,7 @@ async def bind_threepid(
197
195
except TimeoutError :
198
196
raise SynapseError (500 , "Timed out contacting identity server" )
199
197
except CodeMessageException as e :
200
- data = json . loads (e .msg ) # XXX WAT?
198
+ data = json_decoder . decode (e .msg ) # XXX WAT?
201
199
return data
202
200
203
201
logger .info ("Got 404 when POSTing JSON %s, falling back to v1 URL" , bind_url )
@@ -620,18 +618,19 @@ async def proxy_msisdn_submit_token(
620
618
# the CS API. They should be consolidated with those in RoomMemberHandler
621
619
# https://github.com/matrix-org/synapse-dinsic/issues/25
622
620
623
- @defer .inlineCallbacks
624
- def proxy_lookup_3pid (self , id_server , medium , address ):
621
+ async def proxy_lookup_3pid (
622
+ self , id_server : str , medium : str , address : str
623
+ ) -> JsonDict :
625
624
"""Looks up a 3pid in the passed identity server.
626
625
627
626
Args:
628
- id_server (str) : The server name (including port, if required)
627
+ id_server: The server name (including port, if required)
629
628
of the identity server to use.
630
- medium (str) : The type of the third party identifier (e.g. "email").
631
- address (str) : The third party identifier (e.g. "foo@example.com").
629
+ medium: The type of the third party identifier (e.g. "email").
630
+ address: The third party identifier (e.g. "foo@example.com").
632
631
633
632
Returns:
634
- Deferred[dict]: The result of the lookup. See
633
+ The result of the lookup. See
635
634
https://matrix.org/docs/spec/identity_service/r0.1.0.html#association-lookup
636
635
for details
637
636
"""
@@ -643,16 +642,11 @@ def proxy_lookup_3pid(self, id_server, medium, address):
643
642
id_server_url = self .rewrite_id_server_url (id_server , add_https = True )
644
643
645
644
try :
646
- data = yield self .http_client .get_json (
645
+ data = await self .http_client .get_json (
647
646
"%s/_matrix/identity/api/v1/lookup" % (id_server_url ,),
648
647
{"medium" : medium , "address" : address },
649
648
)
650
649
651
- if "mxid" in data :
652
- if "signatures" not in data :
653
- raise AuthError (401 , "No signatures on 3pid binding" )
654
- yield self ._verify_any_signature (data , id_server )
655
-
656
650
except HttpResponseException as e :
657
651
logger .info ("Proxied lookup failed: %r" , e )
658
652
raise e .to_synapse_error ()
@@ -662,18 +656,19 @@ def proxy_lookup_3pid(self, id_server, medium, address):
662
656
663
657
return data
664
658
665
- @defer .inlineCallbacks
666
- def proxy_bulk_lookup_3pid (self , id_server , threepids ):
659
+ async def proxy_bulk_lookup_3pid (
660
+ self , id_server : str , threepids : List [List [str ]]
661
+ ) -> JsonDict :
667
662
"""Looks up given 3pids in the passed identity server.
668
663
669
664
Args:
670
- id_server (str) : The server name (including port, if required)
665
+ id_server: The server name (including port, if required)
671
666
of the identity server to use.
672
- threepids ([[str, str]]) : The third party identifiers to lookup, as
667
+ threepids: The third party identifiers to lookup, as
673
668
a list of 2-string sized lists ([medium, address]).
674
669
675
670
Returns:
676
- Deferred[dict]: The result of the lookup. See
671
+ The result of the lookup. See
677
672
https://matrix.org/docs/spec/identity_service/r0.1.0.html#association-lookup
678
673
for details
679
674
"""
@@ -685,7 +680,7 @@ def proxy_bulk_lookup_3pid(self, id_server, threepids):
685
680
id_server_url = self .rewrite_id_server_url (id_server , add_https = True )
686
681
687
682
try :
688
- data = yield self .http_client .post_json_get_json (
683
+ data = await self .http_client .post_json_get_json (
689
684
"%s/_matrix/identity/api/v1/bulk_lookup" % (id_server_url ,),
690
685
{"threepids" : threepids },
691
686
)
@@ -697,7 +692,7 @@ def proxy_bulk_lookup_3pid(self, id_server, threepids):
697
692
logger .info ("Failed to contact %s: %s" , id_server , e )
698
693
raise ProxiedRequestError (503 , "Failed to contact identity server" )
699
694
700
- defer . returnValue ( data )
695
+ return data
701
696
702
697
async def lookup_3pid (
703
698
self ,
0 commit comments