Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Relay M_TOKEN_INCORRECT as per MSC4183 #17625

Draft
wants to merge 3 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/17625.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Relay M_TOKEN_INCORRECT from submitToken endpoint as per MSC4183.
4 changes: 4 additions & 0 deletions synapse/api/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ class Codes(str, Enum):
CAPTCHA_INVALID = "M_CAPTCHA_INVALID"
MISSING_PARAM = "M_MISSING_PARAM"
INVALID_PARAM = "M_INVALID_PARAM"
SESSION_EXPIRED = "M_SESSION_EXPIRED"
TOO_LARGE = "M_TOO_LARGE"
EXCLUSIVE = "M_EXCLUSIVE"
THREEPID_AUTH_FAILED = "M_THREEPID_AUTH_FAILED"
Expand Down Expand Up @@ -132,6 +133,9 @@ class Codes(str, Enum):
# connection.
UNKNOWN_POS = "M_UNKNOWN_POS"

# MSC4183: The token supplied to validate a 3pid was not correct
TOKEN_INCORRECT = "M_TOKEN_INCORRECT"


class CodeMessageException(RuntimeError):
"""An exception with integer code, a message string attributes and optional headers.
Expand Down
16 changes: 14 additions & 2 deletions synapse/handlers/identity.py
Original file line number Diff line number Diff line change
Expand Up @@ -535,8 +535,20 @@ async def proxy_msisdn_submit_token(
except RequestTimedOutError:
raise SynapseError(500, "Timed out contacting identity server")
except HttpResponseException as e:
logger.warning("Error contacting msisdn account_threepid_delegate: %s", e)
raise SynapseError(400, "Error contacting the identity server")
synapse_error = e.to_synapse_error()
if synapse_error.errcode == Codes.TOKEN_INCORRECT:
raise SynapseError(
400, "Token incorrect", errcode=Codes.TOKEN_INCORRECT
)
elif synapse_error.errcode == Codes.SESSION_EXPIRED:
raise SynapseError(
400, "Session expired", errcode=Codes.SESSION_EXPIRED
)
else:
logger.warning(
"Error contacting msisdn account_threepid_delegate: %s", e
)
raise SynapseError(400, "Error contacting the identity server")

async def lookup_3pid(
self, id_server: str, medium: str, address: str, id_access_token: str
Expand Down
Loading