mirror of
https://git.anonymousland.org/anonymousland/synapse-product.git
synced 2024-10-01 08:25:44 -04:00
Add POST /_matrix/client/r0/account/3pid/unbind (MSC2140) (#5980)
Implements `POST /_matrix/client/r0/account/3pid/unbind` from [MSC2140](https://github.com/matrix-org/matrix-doc/blob/dbkr/tos_2/proposals/2140-terms-of-service-2.md#post-_matrixclientr0account3pidunbind).
This commit is contained in:
parent
b736c6cd3a
commit
90d17a3d28
1
changelog.d/5980.feature
Normal file
1
changelog.d/5980.feature
Normal file
@ -0,0 +1 @@
|
|||||||
|
Add POST /_matrix/client/r0/account/3pid/unbind endpoint from MSC2140 for unbinding a 3PID from an identity server without removing it from the homeserver user account.
|
@ -137,7 +137,8 @@ class IdentityHandler(BaseHandler):
|
|||||||
|
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
def try_unbind_threepid(self, mxid, threepid):
|
def try_unbind_threepid(self, mxid, threepid):
|
||||||
"""Removes a binding from an identity server
|
"""Attempt to remove a 3PID from an identity server, or if one is not provided, all
|
||||||
|
identity servers we're aware the binding is present on
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
mxid (str): Matrix user ID of binding to be removed
|
mxid (str): Matrix user ID of binding to be removed
|
||||||
|
@ -571,6 +571,38 @@ class ThreepidRestServlet(RestServlet):
|
|||||||
return 200, {}
|
return 200, {}
|
||||||
|
|
||||||
|
|
||||||
|
class ThreepidUnbindRestServlet(RestServlet):
|
||||||
|
PATTERNS = client_patterns("/account/3pid/unbind$")
|
||||||
|
|
||||||
|
def __init__(self, hs):
|
||||||
|
super(ThreepidUnbindRestServlet, self).__init__()
|
||||||
|
self.hs = hs
|
||||||
|
self.identity_handler = hs.get_handlers().identity_handler
|
||||||
|
self.auth = hs.get_auth()
|
||||||
|
self.datastore = self.hs.get_datastore()
|
||||||
|
|
||||||
|
@defer.inlineCallbacks
|
||||||
|
def on_POST(self, request):
|
||||||
|
"""Unbind the given 3pid from a specific identity server, or identity servers that are
|
||||||
|
known to have this 3pid bound
|
||||||
|
"""
|
||||||
|
requester = yield self.auth.get_user_by_req(request)
|
||||||
|
body = parse_json_object_from_request(request)
|
||||||
|
assert_params_in_dict(body, ["medium", "address"])
|
||||||
|
|
||||||
|
medium = body.get("medium")
|
||||||
|
address = body.get("address")
|
||||||
|
id_server = body.get("id_server")
|
||||||
|
|
||||||
|
# Attempt to unbind the threepid from an identity server. If id_server is None, try to
|
||||||
|
# unbind from all identity servers this threepid has been added to in the past
|
||||||
|
result = yield self.identity_handler.try_unbind_threepid(
|
||||||
|
requester.user.to_string(),
|
||||||
|
{"address": address, "medium": medium, "id_server": id_server},
|
||||||
|
)
|
||||||
|
return 200, {"id_server_unbind_result": "success" if result else "no-support"}
|
||||||
|
|
||||||
|
|
||||||
class ThreepidDeleteRestServlet(RestServlet):
|
class ThreepidDeleteRestServlet(RestServlet):
|
||||||
PATTERNS = client_patterns("/account/3pid/delete$")
|
PATTERNS = client_patterns("/account/3pid/delete$")
|
||||||
|
|
||||||
@ -629,5 +661,6 @@ def register_servlets(hs, http_server):
|
|||||||
EmailThreepidRequestTokenRestServlet(hs).register(http_server)
|
EmailThreepidRequestTokenRestServlet(hs).register(http_server)
|
||||||
MsisdnThreepidRequestTokenRestServlet(hs).register(http_server)
|
MsisdnThreepidRequestTokenRestServlet(hs).register(http_server)
|
||||||
ThreepidRestServlet(hs).register(http_server)
|
ThreepidRestServlet(hs).register(http_server)
|
||||||
|
ThreepidUnbindRestServlet(hs).register(http_server)
|
||||||
ThreepidDeleteRestServlet(hs).register(http_server)
|
ThreepidDeleteRestServlet(hs).register(http_server)
|
||||||
WhoamiRestServlet(hs).register(http_server)
|
WhoamiRestServlet(hs).register(http_server)
|
||||||
|
Loading…
Reference in New Issue
Block a user