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

Allow HS to send emails when adding an email to the HS #6042

Merged
merged 47 commits into from
Sep 20, 2019
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
0e5d92d
Allow HS to send emails when adding an email to the HS
anoadragon453 Sep 16, 2019
92b3246
Add changelog
anoadragon453 Sep 16, 2019
626ebbd
Add changelog
anoadragon453 Sep 17, 2019
8132107
Add 'add threepid' email templates to config. Gen sample config
anoadragon453 Sep 17, 2019
d309ea2
Merge branch 'develop' into anoa/account_3pid_homeserver
anoadragon453 Sep 17, 2019
112d55e
Merge branch 'anoa/account_3pid_homeserver' into anoa/account_3pid_ho…
anoadragon453 Sep 17, 2019
096808b
Add 3PID bind sytests to blacklist temporarily
anoadragon453 Sep 17, 2019
268bbbb
Prevent /account/3pid from binding to an identity server
anoadragon453 Sep 17, 2019
dda5137
Correct some small issues and fix bug
anoadragon453 Sep 17, 2019
8e2481b
Address review comments
anoadragon453 Sep 18, 2019
f6c0d5c
Remove the requirement for a medium argument
anoadragon453 Sep 18, 2019
923736f
Handle the homeserver disabling email validation
anoadragon453 Sep 18, 2019
4fc7796
Remove blacklist
anoadragon453 Sep 18, 2019
15bf108
Fix add_threepid template default values in emailconfig
anoadragon453 Sep 18, 2019
d20feec
Remove redundant logging
anoadragon453 Sep 18, 2019
0e5c7bf
Undo fix on password reset POST submit_token endpoint
anoadragon453 Sep 18, 2019
46da943
Update synapse/storage/registration.py
anoadragon453 Sep 18, 2019
3941439
Use an assert instead of if-statement with SynapseError
anoadragon453 Sep 18, 2019
0200e41
Remove trailing slashes from submit_token endpoint patterns
anoadragon453 Sep 18, 2019
c8dbf53
python3 super()
anoadragon453 Sep 18, 2019
d32724b
Remove self.hs set from AddThreepidSubmitTokenServlet
anoadragon453 Sep 18, 2019
0812664
Clarify changelog
anoadragon453 Sep 18, 2019
9309ca5
Merge branch 'anoa/account_3pid_homeserver_send_email' of github.com:…
anoadragon453 Sep 18, 2019
46e6d92
Sanity check ThreepidBehaviour.REMOTE on submit_token endpoint
anoadragon453 Sep 18, 2019
b37d71c
Re-blacklist tests
anoadragon453 Sep 18, 2019
16eb35d
Factor out removing id_server from msisdn
anoadragon453 Sep 18, 2019
16d7ec2
Remove POST /add_threepid/<medium>/submit_token
anoadragon453 Sep 18, 2019
ab1ae2f
Ensure REMOTE vs LOCAL ThreepidBehaviour is handled
anoadragon453 Sep 19, 2019
1be82f8
URL encode validation link parameters
anoadragon453 Sep 19, 2019
317332e
Move jinja failure template loading into servlet constructor
anoadragon453 Sep 19, 2019
59e0aad
Make add_threepid submit_token email-only
anoadragon453 Sep 19, 2019
882642e
Make get_threepid_validation_session require client_secret
anoadragon453 Sep 19, 2019
1464f14
Update changelog entry
anoadragon453 Sep 19, 2019
fb9c582
Set email
anoadragon453 Sep 19, 2019
f62ddf6
Make sure templates only get loaded when necessary
anoadragon453 Sep 19, 2019
0dcdfbb
Remove unnecessary vars and params
anoadragon453 Sep 20, 2019
d683ae5
Ensure link is not a tuple
anoadragon453 Sep 20, 2019
f62a27c
Pull if validation_session out of helper method
anoadragon453 Sep 20, 2019
ac92a58
this confused me for so long
anoadragon453 Sep 20, 2019
38a543c
Don't force https on account_threepid_delegates
anoadragon453 Sep 20, 2019
2f296c7
Merge branch 'develop' of github.com:matrix-org/synapse into anoa/acc…
anoadragon453 Sep 20, 2019
b12e51a
Ensure we catch HttpResponseException when calling to id servers
anoadragon453 Sep 20, 2019
1267abd
Unpack response from identity server to check for errors
anoadragon453 Sep 20, 2019
b3bf430
Remove prefix nonsense
anoadragon453 Sep 20, 2019
227ec33
Factor out password_reset trailing slash change
anoadragon453 Sep 20, 2019
4efc108
Address review comments
anoadragon453 Sep 20, 2019
7c351df
validation_session cannot be None
anoadragon453 Sep 20, 2019
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
5 changes: 1 addition & 4 deletions synapse/handlers/identity.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,7 @@ def threepid_from_creds(self, id_server, creds):

query_params = {"sid": session_id, "client_secret": client_secret}

url = "https://%s%s" % (
id_server,
"/_matrix/identity/api/v1/3pid/getValidated3pid",
)
url = "%s%s" % (id_server, "/_matrix/identity/api/v1/3pid/getValidated3pid")
anoadragon453 marked this conversation as resolved.
Show resolved Hide resolved

data = yield self.http_client.get_json(url, query_params)
return data if "medium" in data else None
Expand Down
2 changes: 1 addition & 1 deletion synapse/push/mailer.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ def send_add_threepid_mail(self, email_address, token, client_secret, sid):
link = (
self.hs.config.public_baseurl
+ "_matrix/client/unstable/add_threepid/email/submit_token?%s"
% urllib.parse.urlencode(params),
% urllib.parse.urlencode(params)
)

template_vars = {"link": link}
Expand Down
47 changes: 26 additions & 21 deletions synapse/rest/client/v2_alpha/account.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,12 @@
from twisted.internet import defer

from synapse.api.constants import LoginType
from synapse.api.errors import Codes, SynapseError, ThreepidValidationError
from synapse.api.errors import (
Codes,
HttpResponseException,
SynapseError,
ThreepidValidationError,
)
from synapse.config.emailconfig import ThreepidBehaviour
from synapse.http.server import finish_request
from synapse.http.servlet import (
Expand Down Expand Up @@ -193,7 +198,7 @@ class PasswordResetSubmitTokenServlet(RestServlet):
"""Handles 3PID validation token submission"""

PATTERNS = client_patterns(
"/password_reset/(?P<medium>[^/]*)/submit_token$", releases=(), unstable=True
"/password_reset/(?P<medium>[^/]*)/submit_token/*$", releases=(), unstable=True
richvdh marked this conversation as resolved.
Show resolved Hide resolved
)

def __init__(self, hs):
Expand Down Expand Up @@ -524,7 +529,6 @@ def __init__(self, hs):
hs (synapse.server.HomeServer): server
"""
super().__init__()
self.auth = hs.get_auth()
self.config = hs.config
self.clock = hs.get_clock()
self.store = hs.get_datastore()
Expand All @@ -535,7 +539,7 @@ def __init__(self, hs):
)

@defer.inlineCallbacks
def on_GET(self, request, medium):
def on_GET(self, request):
if self.config.threepid_behaviour_email == ThreepidBehaviour.OFF:
anoadragon453 marked this conversation as resolved.
Show resolved Hide resolved
if self.config.local_threepid_handling_disabled_due_to_email_config:
logger.warn(
Expand Down Expand Up @@ -630,34 +634,43 @@ def on_POST(self, request):
# Try to validate as email
if self.hs.config.threepid_behaviour_email == ThreepidBehaviour.REMOTE:
# Ask our delegated email identity server
validation_session = yield self.identity_handler.threepid_from_creds(
self.hs.config.account_threepid_delegate_email, threepid_creds
)
try:
validation_session = yield self.identity_handler.threepid_from_creds(
self.hs.config.account_threepid_delegate_email, threepid_creds
)
except HttpResponseException:
pass
anoadragon453 marked this conversation as resolved.
Show resolved Hide resolved
elif self.hs.config.threepid_behaviour_email == ThreepidBehaviour.LOCAL:
# Get a validated session matching these details
validation_session = yield self.datastore.get_threepid_validation_session(
"email", client_secret, sid=sid, validated=True
)

if self._add_threepid_to_account(user_id, validation_session):
if validation_session and "error" not in validation_session:
anoadragon453 marked this conversation as resolved.
Show resolved Hide resolved
yield self._add_threepid_to_account(user_id, validation_session)
return 200, {}

# Try to validate as msisdn
if self.hs.config.account_threepid_delegate_msisdn:
# Ask our delegated msisdn identity server
validation_session = yield self.identity_handler.threepid_from_creds(
self.hs.config.account_threepid_delegate_msisdn, threepid_creds
)
try:
validation_session = yield self.identity_handler.threepid_from_creds(
self.hs.config.account_threepid_delegate_msisdn, threepid_creds
)
except HttpResponseException:
pass

if self._add_threepid_to_account(user_id, validation_session):
if validation_session and "error" not in validation_session:
yield self._add_threepid_to_account(user_id, validation_session)
return 200, {}

raise SynapseError(
400, "No validated 3pid session found", Codes.THREEPID_AUTH_FAILED
)

@defer.inlineCallbacks
def _add_threepid_to_account(self, user_id, validation_session):
"""Attempt to add a threepid wrapped in a validation_session dict to an account
"""Add a threepid wrapped in a validation_session dict to an account

Args:
user_id (str): The mxid of the user to add this 3PID to
Expand All @@ -668,22 +681,14 @@ def _add_threepid_to_account(self, user_id, validation_session):
* validated_at - timestamp of when the validation occurred

If validation_session is None, this method will return False
anoadragon453 marked this conversation as resolved.
Show resolved Hide resolved

Returns:
A boolean stating whether adding the threepid was successful
"""
if not validation_session:
return False

yield self.auth_handler.add_threepid(
user_id,
validation_session["medium"],
validation_session["address"],
validation_session["validated_at"],
)

return True


class ThreepidUnbindRestServlet(RestServlet):
PATTERNS = client_patterns("/account/3pid/unbind$", releases=(), unstable=True)
Expand Down
2 changes: 1 addition & 1 deletion sytest-blacklist
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,4 @@ Can bind 3PID via home server
Can bind and unbind 3PID via homeserver
3PIDs are unbound after account deactivation
Can bind and unbind 3PID via /unbind by specifying the identity server
Can bind and unbind 3PID via /unbind without specifying the identity server
Can bind and unbind 3PID via /unbind without specifying the identity server