-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Drop support for calling /_matrix/client/v3/account/3pid/bind
without an id_access_token
#13239
Changes from 2 commits
7212a68
1084c5d
c55b3ec
f8baf96
df50b11
026c583
7eefc79
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Drop v1 3pid bind support. | ||
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -164,7 +164,6 @@ async def bind_threepid( | |||
mxid: str, | ||||
id_server: str, | ||||
id_access_token: Optional[str] = None, | ||||
use_v2: bool = True, | ||||
) -> JsonDict: | ||||
"""Bind a 3PID to an identity server | ||||
|
||||
|
@@ -175,10 +174,10 @@ async def bind_threepid( | |||
id_server: The domain of the identity server to query | ||||
id_access_token: The access token to authenticate to the identity | ||||
server with, if necessary. Required if use_v2 is true | ||||
use_v2: Whether to use v2 Identity Service API endpoints. Defaults to True | ||||
|
||||
Raises: | ||||
SynapseError: On any of the following conditions | ||||
- no id_access_token was supplied | ||||
- the supplied id_server is not a valid identity server name | ||||
- we failed to contact the supplied identity server | ||||
|
||||
|
@@ -187,9 +186,10 @@ async def bind_threepid( | |||
""" | ||||
logger.debug("Proxying threepid bind request for %s to %s", mxid, id_server) | ||||
|
||||
# If an id_access_token is not supplied, force usage of v1 | ||||
if id_access_token is None: | ||||
use_v2 = False | ||||
raise SynapseError( | ||||
400, "id_access_token is required", errcode=Codes.MISSING_PARAM | ||||
) | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This sort of validation should be handled at the rest level, see here: synapse/synapse/rest/client/account.py Line 749 in aa5f5ed
Additionally, the current function should be changed so that |
||||
|
||||
if not valid_id_server_location(id_server): | ||||
raise SynapseError( | ||||
|
@@ -198,13 +198,9 @@ async def bind_threepid( | |||
) | ||||
|
||||
# Decide which API endpoint URLs to use | ||||
headers = {} | ||||
bind_data = {"sid": sid, "client_secret": client_secret, "mxid": mxid} | ||||
if use_v2: | ||||
bind_url = "https://%s/_matrix/identity/v2/3pid/bind" % (id_server,) | ||||
headers["Authorization"] = create_id_access_token_header(id_access_token) # type: ignore | ||||
else: | ||||
bind_url = "https://%s/_matrix/identity/api/v1/3pid/bind" % (id_server,) | ||||
bind_url = "https://%s/_matrix/identity/v2/3pid/bind" % (id_server,) | ||||
headers = {"Authorization": create_id_access_token_header(id_access_token)} | ||||
|
||||
try: | ||||
# Use the blacklisting http client as this call is only to identity servers | ||||
|
@@ -223,20 +219,15 @@ async def bind_threepid( | |||
|
||||
return data | ||||
except HttpResponseException as e: | ||||
if e.code != 404 or not use_v2: | ||||
if e.code != 404: | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this line wants to be deleted? I.e. treat a 404 like any other error? |
||||
logger.error("3PID bind failed with Matrix error: %r", e) | ||||
raise e.to_synapse_error() | ||||
except RequestTimedOutError: | ||||
raise SynapseError(500, "Timed out contacting identity server") | ||||
except CodeMessageException as e: | ||||
data = json_decoder.decode(e.msg) # XXX WAT? | ||||
return data | ||||
|
||||
logger.info("Got 404 when POSTing JSON %s, falling back to v1 URL", bind_url) | ||||
res = await self.bind_threepid( | ||||
client_secret, sid, mxid, id_server, id_access_token, use_v2=False | ||||
) | ||||
return res | ||||
return {} | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think returning an empty dict in the 404 case makes sense here. Instead, I think we should treat 404 like all other errors, which will make this line unreachable. |
||||
|
||||
async def try_unbind_threepid(self, mxid: str, threepid: dict) -> bool: | ||||
"""Attempt to remove a 3PID from an identity server, or if one is not provided, all | ||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are a few things called 3pid/bind here. I think it is worth being more precise.
Additionally, this should be
13239.removal
, not.misc
.