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

Commit d7252d9

Browse files
committed
Add POST /_matrix/client/r0/account/3pid/unbind (MSC2140) (#5980)
2 parents 394ec9c + 90d17a3 commit d7252d9

File tree

3 files changed

+36
-1
lines changed

3 files changed

+36
-1
lines changed

changelog.d/5980.feature

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
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.

synapse/handlers/identity.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,8 @@ def bind_threepid(self, creds, mxid):
155155

156156
@defer.inlineCallbacks
157157
def try_unbind_threepid(self, mxid, threepid):
158-
"""Removes a binding from an identity server
158+
"""Attempt to remove a 3PID from an identity server, or if one is not provided, all
159+
identity servers we're aware the binding is present on
159160
160161
Args:
161162
mxid (str): Matrix user ID of binding to be removed

synapse/rest/client/v2_alpha/account.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -641,6 +641,38 @@ def shadow_3pid(self, body, user_id):
641641
)
642642

643643

644+
class ThreepidUnbindRestServlet(RestServlet):
645+
PATTERNS = client_patterns("/account/3pid/unbind$")
646+
647+
def __init__(self, hs):
648+
super(ThreepidUnbindRestServlet, self).__init__()
649+
self.hs = hs
650+
self.identity_handler = hs.get_handlers().identity_handler
651+
self.auth = hs.get_auth()
652+
self.datastore = self.hs.get_datastore()
653+
654+
@defer.inlineCallbacks
655+
def on_POST(self, request):
656+
"""Unbind the given 3pid from a specific identity server, or identity servers that are
657+
known to have this 3pid bound
658+
"""
659+
requester = yield self.auth.get_user_by_req(request)
660+
body = parse_json_object_from_request(request)
661+
assert_params_in_dict(body, ["medium", "address"])
662+
663+
medium = body.get("medium")
664+
address = body.get("address")
665+
id_server = body.get("id_server")
666+
667+
# Attempt to unbind the threepid from an identity server. If id_server is None, try to
668+
# unbind from all identity servers this threepid has been added to in the past
669+
result = yield self.identity_handler.try_unbind_threepid(
670+
requester.user.to_string(),
671+
{"address": address, "medium": medium, "id_server": id_server},
672+
)
673+
return 200, {"id_server_unbind_result": "success" if result else "no-support"}
674+
675+
644676
class ThreepidDeleteRestServlet(RestServlet):
645677
PATTERNS = client_patterns("/account/3pid/delete$")
646678

@@ -781,6 +813,7 @@ def register_servlets(hs, http_server):
781813
EmailThreepidRequestTokenRestServlet(hs).register(http_server)
782814
MsisdnThreepidRequestTokenRestServlet(hs).register(http_server)
783815
ThreepidRestServlet(hs).register(http_server)
816+
ThreepidUnbindRestServlet(hs).register(http_server)
784817
ThreepidDeleteRestServlet(hs).register(http_server)
785818
ThreepidLookupRestServlet(hs).register(http_server)
786819
ThreepidBulkLookupRestServlet(hs).register(http_server)

0 commit comments

Comments
 (0)