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

Add submit_url response parameter to msisdn /requestToken #6079

Merged
merged 17 commits into from
Sep 23, 2019
Merged
Show file tree
Hide file tree
Changes from 13 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/6079.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add `submit_url` response parameter to /account/3pid/msisdn/requestToken`.
1 change: 1 addition & 0 deletions docs/sample_config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -937,6 +937,7 @@ uploads_path: "DATADIR/uploads"
# by the Matrix Identity Service API specification:
# https://matrix.org/docs/spec/identity_service/latest
#
# If a delegate is specified, the config option public_baseurl must also be filled out.
richvdh marked this conversation as resolved.
Show resolved Hide resolved
account_threepid_delegates:
#email: https://example.com # Delegate email sending to example.org
#msisdn: http://localhost:8090 # Delegate SMS sending to this local process
Expand Down
1 change: 1 addition & 0 deletions synapse/config/registration.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,7 @@ def generate_config_section(self, generate_secrets=False, **kwargs):
# by the Matrix Identity Service API specification:
# https://matrix.org/docs/spec/identity_service/latest
#
# If a delegate is specified, the config option public_baseurl must also be filled out.
richvdh marked this conversation as resolved.
Show resolved Hide resolved
account_threepid_delegates:
#email: https://example.com # Delegate email sending to example.org
#msisdn: http://localhost:8090 # Delegate SMS sending to this local process
Expand Down
34 changes: 34 additions & 0 deletions synapse/handlers/identity.py
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,40 @@ def proxy_msisdn_submit_token(self, id_server, client_secret, sid, token):
logger.warning("Error contacting msisdn account_threepid_delegate: %s", e)
raise SynapseError(400, "Error contacting the identity server")

@defer.inlineCallbacks
def proxy_msisdn_submit_token(self, id_server, client_secret, sid, token):
"""Proxy a POST submitToken request to an identity server for verification purposes

Args:
id_server (str): The identity server URL to contact

client_secret (str): Secret provided by the client

sid (str): The ID of the session

token (str): The verification token

Raises:
SynapseError: If we failed to contact the identity server

Returns:
Deferred[dict]: The response dict from the identity server
"""
body = {"client_secret": client_secret, "sid": sid, "token": token}

try:
return (
yield self.http_client.post_json_get_json(
id_server + "/_matrix/identity/api/v1/validate/msisdn/submitToken",
body,
)
)
except TimeoutError:
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")


def create_id_access_token_header(id_access_token):
"""Create an Authorization header for passing to SimpleHttpClient as the header value
Expand Down
8 changes: 8 additions & 0 deletions synapse/rest/client/v2_alpha/account.py
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,14 @@ def on_POST(self, request):
next_link,
)

assert self.hs.config.public_baseurl

# Add submit_url response parameter as per MSC2078
ret["submit_url"] = (
self.hs.config.public_baseurl
+ "_matrix/client/unstable/add_threepid/msisdn/submit_token"
)

return 200, ret


Expand Down