diff --git a/synapse/rest/client/v2_alpha/account.py b/synapse/rest/client/v2_alpha/account.py
index 7e5884df0c..752ea265bd 100644
--- a/synapse/rest/client/v2_alpha/account.py
+++ b/synapse/rest/client/v2_alpha/account.py
@@ -480,6 +480,38 @@ class ThreepidDeleteRestServlet(RestServlet):
)
+class ThreepidLookupRestServlet(RestServlet):
+ PATTERNS = client_v2_patterns("/account/3pid/lookup$")
+
+ def __init__(self, hs):
+ super(ThreepidLookupRestServlet, self).__init__()
+ self.config = hs.config
+ self.auth = hs.get_auth()
+ self.identity_handler = IdentityHandler(hs)
+
+ @defer.inlineCallbacks
+ def on_GET(self, request):
+ """Proxy a /_matrix/identity/api/v1/lookup request to an identity
+ server
+ """
+ yield self.auth.get_user_by_req(request)
+
+ # Extract query parameters
+ query_params = request.args
+ assert_params_in_dict(query_params, [b"medium", b"address", b"id_server"])
+
+ # Retrieve address and medium from the request parameters
+ medium = parse_string(request, "medium")
+ address = parse_string(request, "address")
+ id_server = parse_string(request, "id_server")
+
+ # Proxy the request to the identity server. lookup_3pid handles checking
+ # if the lookup is allowed so we don't need to do it here.
+ ret = yield self.identity_handler.lookup_3pid(id_server, medium, address)
+
+ respond_with_json(200, ret)
+
+
class WhoamiRestServlet(RestServlet):
PATTERNS = client_v2_patterns("/account/whoami$")
diff --git a/synapse/rest/identity/__init__.py b/synapse/rest/identity/__init__.py
deleted file mode 100644
index 1453d04571..0000000000
--- a/synapse/rest/identity/__init__.py
+++ /dev/null
@@ -1,14 +0,0 @@
-# -*- coding: utf-8 -*-
-# Copyright 2019 New Vector Ltd
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
diff --git a/synapse/rest/identity/v1/__init__.py b/synapse/rest/identity/v1/__init__.py
deleted file mode 100644
index 09057ea16b..0000000000
--- a/synapse/rest/identity/v1/__init__.py
+++ /dev/null
@@ -1,24 +0,0 @@
-# -*- coding: utf-8 -*-
-# Copyright 2019 New Vector Ltd
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-from twisted.web.resource import Resource
-
-from .lookup import IdentityLookup
-
-
-class IdentityApiV1Resource(Resource):
- def __init__(self, hs):
- Resource.__init__(self)
- self.putChild(b"lookup", IdentityLookup(hs))
diff --git a/synapse/rest/identity/v1/lookup.py b/synapse/rest/identity/v1/lookup.py
deleted file mode 100644
index c2d18fbb63..0000000000
--- a/synapse/rest/identity/v1/lookup.py
+++ /dev/null
@@ -1,70 +0,0 @@
-# -*- coding: utf-8 -*-
-# Copyright 2019 New Vector Ltd
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-
-import logging
-
-from twisted.internet import defer
-from twisted.web.resource import Resource
-from twisted.web.server import NOT_DONE_YET
-
-from synapse.api.errors import SynapseError
-from synapse.handlers.identity import IdentityHandler
-from synapse.http.server import respond_with_json, wrap_json_request_handler
-from synapse.http.servlet import assert_params_in_dict, parse_string
-
-logger = logging.getLogger(__name__)
-
-
-class IdentityLookup(Resource):
- isLeaf = True
-
- def __init__(self, hs):
- self.config = hs.config
- self.auth = hs.get_auth()
- self.identity_handler = IdentityHandler(hs)
- Resource.__init__(self)
-
- def render_GET(self, request):
- self.async_render_GET(request)
- return NOT_DONE_YET
-
- @wrap_json_request_handler
- @defer.inlineCallbacks
- def async_render_GET(self, request):
- """Proxy a /_matrix/identity/api/v1/lookup request to an identity
- server
- """
- yield self.auth.get_user_by_req(request, allow_guest=True)
-
- if not self.config.enable_3pid_lookup:
- raise SynapseError(
- 403,
- "Looking up third-party identifiers is denied from this server"
- )
-
- # Extract query parameters
- query_params = request.args
- assert_params_in_dict(query_params, [b"medium", b"address", b"is_server"])
-
- # Retrieve address and medium from the request parameters
- medium = parse_string(request, "medium")
- address = parse_string(request, "address")
- is_server = parse_string(request, "is_server")
-
- # Proxy the request to the identity server
- ret = yield self.identity_handler.lookup_3pid(is_server, medium, address)
-
- respond_with_json(request, 200, ret, send_cors=True)
|